marshmallow-code / marshmallow-code/marshmallow
Remove `only`, `exclude`, `many`, and `unknown` parameters of `Nested` and require callables to return Schema instances
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 738
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 7
Description
Proposing the following 2 changes to `fields.Nested`:
(1) drop support for passing callables that return schema classes and dicts (e.g. `lambda: CSchema`) and only support callables that return instances (`lambda: CSchema()`).
**Before:**
```python
nested: (
Schema
| SchemaMeta
| str
| dict[str, Field]
| typing.Callable[[], Schema | SchemaMeta | dict[str, Field]]
),
```
**After:**
```python
nested: (
Schema | SchemaMeta | str | dict[str, Field] | typing.Callable[[], Schema]
),
```
And (2) deprecate the `only`, `exclude`, `many`, and `unknown` parameters of `Nested`.
Final end state of `fields.Nested` would be
```python
def __init__(
self,
nested: (
Schema | SchemaMeta | str | dict[str, Field] | typing.Callable[[], Schema]
),
**kwargs: Unpack[_BaseFieldKwargs],
):
```
## Why?
It would vastly both the usage and the internal implementation of `Nested`. This eliminates a class of bugs where the `nested` argument conflicts with `only`, `exclude`, `many`, and `unknown`.
See https://github.com/marshmallow-code/marshmallow/issues/2165 for an example of this.
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 locating fields.Nested and reviewing the conflicting behavior described in issue #2165. Trace its handling of callable return values and the only, exclude, many, and unknown parameters, then inspect related tests or usages. Done means the deprecation and callable contract are implemented consistently with coverage for the final API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100