marshmallow-code / marshmallow-code/marshmallow
Add decorator syntax for method fields?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 738
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 7
Description
The current syntax for method fields is somewhat awkward, especially around naming:
```python
class MySchema(Schema):
is_valid = fields.Method('get_is_valid')
def get_is_valid(obj):
return something_something_something(obj)
```
At a slight cost to consistency, we could make this more ergonomic with syntax like:
```python
class MySchema(Schema):
@fields.method
def is_valid(obj):
return something_something_something(obj)
```
And/or:
```python
class MySchema(Schema):
@fields.method(dump_to='foo')
def is_valid(obj):
return something_something_something(obj)
```
Does this sound reasonable?
If so, is the naming okay? And should `@fields.method` be allowed as shorthand when not passing any other arguments in setting up the field, or should it always be `@fields.method()`?
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
The issue names no files or tests. Start by locating the existing fields.Method implementation and the Schema field-declaration handling, then review the proposed decorator forms and their naming options. Done would require an agreed API design plus corresponding implementation and test coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100