marshmallow-code / marshmallow-code/marshmallow
A better name for validation related module (`marshmallow.validate`), decorator (`@validates`), and field argument (`validate=`)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 738
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 7
Description
IMO, the current name of validation-related is not intuitive enough. The following API should be changed:
- The `marshamllow.vaildate` module that stores all the validator classes. The `validators` (noun) is used in docs, while the module name is `validate` (verb).
- The decorators used to register a validation method for field or schema: `@validates` and `@validates_schema`. The `s` is quite redundant in my view. Any reasons behind these `validates` names in Marshmallow? is it just because the validate namespace is occupied by the `marshmallow.validate` module?
- The `validate` keyword argument in field classes. The `validate` is a verb, while it used to accept one or more validators.
Proposal:
- Change the module `marshmallow.validate` to `marshmallow.validators`.
- Change the decorator `@validates` to `@validate`.
- Change the decorator `@validates_schema` to `@validate_schema`.
- Change the field argument `validate` to `validator` and `validators`. `validator` accepts one callable; `validators` accepts a list of callable.
Example:
```python
from marshmallow import Schema, validate, validate_schema
from marshmallow.fields import String, Integer
from marshmallow.validators import Length
class PetSchema(Schema):
name = String(required=True, validator=Length(0, 10))
category = String(required=True, validators=[OneOf(['dog', 'cat']), Length(0, 10)])
@validate('name')
def validate_name(...):
pass
@validate_schema
def validate_something(...):
pass
```
Related issues:
- Support validator=, validators=, or validate_with= (#645)
- It seems better changing the validate module to "validators" (#1650)
Originally posted in greyli/apiflask#62
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the marshmallow.validate module, the @validates and @validates_schema decorators, and the field validate argument to map their current public uses. Compare the proposal with related issues #645 and #1650; the work is complete only when the proposed names are applied consistently across the API and its documented examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100