marshmallow-code / marshmallow-code/marshmallow

Move some fields (exclude, only, etc) to private API in `Schema.__init__`

Open
#1,281 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backwards incompat
Dominant language
Python
Stars
7.2k
Forks
738
Avg merge
1d 23h
Merged PRs (30d)
7

Description

I'd make `exclude` and `only` private API because they are used in `_normalize_nested_options` which is called only at `__init__`.

I'd also make `load_only` and `dump_only` private because setting them after `__init__` conflicts with

```py
self.load_only = set(load_only) or set(self.opts.load_only)
self.dump_only = set(dump_only) or set(self.opts.dump_only)
```

Likewise with `unknown` and `context` due to

```py
self.unknown = unknown or self.opts.unknown
self.context = context or {}
```

(setting them to `None` after `__init__` wouldn't be the same as in `__init__`)

At this point, I'm tempted to make everything private. I mean the attributes above plus `many`, `ordered` and `partial`.

Adding the underscore would break libs using marshmallow (like apispec) but that's life. Or is there another way to signify those are private? Like, just a comment in the docstring?

_Originally posted by @lafrech in https://github.com/marshmallow-code/marshmallow/pull/1258#issuecomment-508262389_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading Schema.__init__ and _normalize_nested_options, focusing on exclude, only, load_only, dump_only, unknown, context, many, ordered, and partial. Review the compatibility concern for libraries such as apispec before determining whether these attributes should be private or documented as public. Done requires an agreed API direction and corresponding changes, but the issue does not define that decision or name tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.