Conversation
98a871c to
73cbe0f
Compare
73cbe0f to
a07a40a
Compare
| def meta(*bases, **kwargs): ... | ||
|
|
||
|
|
||
| def meta(*bases, **kwargs): |
There was a problem hiding this comment.
the @overload usage seems a bit odd...does the approach with TypedDict and total=False not work? like what we do here?
marshmallow/src/marshmallow/fields.py
Lines 87 to 98 in f0c6afb
or perhaps
def meta(
*bases: SchemaMeta,
fields: tuple[str, ...] | list[str] | None,
additional: tuple[str, ...] | list[str] | None,
# ...
**kwargs,
):
def wrapper(schema):
mro = bases if bases else (schema.Meta,)
meta = type(schema.Meta.__name__, mro, {
"fields": fields,
"additional": additional,
# ...
**kwargs
})
return type(schema.__name__, (schema,), {"Meta": meta})
return wrapperThere was a problem hiding this comment.
Unpack[TypedDict] does not allow accepting extra kwargs, but we allow custom Meta attributes.
Explicitly copying the args into a dictionary defines missing attributes as None, which breaks inheritance.
One @overloadis all that is needed (and is valid), but mypy requires a sacrificial overload.
There was a problem hiding this comment.
Ah I see. In that case, maybe just add comments about why this approach is necessary. Could even include a link to that gh comment
|
|
||
| @typing.overload | ||
| def meta( | ||
| *bases: SchemaMeta, |
There was a problem hiding this comment.
Should this be
| *bases: SchemaMeta, | |
| *bases: Schema.Meta, |
? Surprised mypy doesn't raise an error in the tests tho 🤔
Add an experimental decorator for declaring meta attributes that inherits by default.
Resolves #1879