marshmallow-code / marshmallow-code/marshmallow

@field decorator to allow methods to return a Field object

Open
#1,419 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
7.2k
Forks
738
Avg merge
1d 23h
Merged PRs (30d)
7

Description

This is different (in my opinion) from issue #738 or [`fields.Method`](https://marshmallow.readthedocs.io/en/stable/api_reference.html#marshmallow.fields.Method).

This request is to define a decorator (maybe named `@field`) to decorate a method that returns a field without taking care of serialization or deserialization. This would be the same as the [`@declared_attr`](https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/api.html?highlight=declared_attr#sqlalchemy.ext.declarative.declared_attr) from SQLAlchemy.

The idea is to define a field which can make use of other class members.

```python
>>> import marshmallow
>>> class MySchema(object):
... def __init__(self, schemes):
... self.schemes = schemes
...
... @marshmallow.field
... def url(self):
... return marshmallow.fields.Url(schemes=self.schemes)
...
```

Contributor guide

Open the contributing guide

Research direction

Start by reviewing marshmallow.fields.Method and the referenced SQLAlchemy declared_attr behavior, then compare them with the proposed @marshmallow.field example. Done means a decorator can create a Field from a method using other schema members, without handling serialization or deserialization; the payload names no implementation files or tests.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.