PEP 681: Add support for kwargs (#2504)
This commit is contained in:
parent
7e537baa97
commit
f73a0aa1ca
15
pep-0681.rst
15
pep-0681.rst
|
@ -221,6 +221,7 @@ customization of default behaviors:
|
|||
order_default: bool = False,
|
||||
kw_only_default: bool = False,
|
||||
field_specifiers: tuple[type | Callable[..., Any], ...] = (),
|
||||
**kwargs: Any,
|
||||
) -> Callable[[_T], _T]: ...
|
||||
|
||||
* ``eq_default`` indicates whether the ``eq`` parameter is assumed to
|
||||
|
@ -245,6 +246,11 @@ customization of default behaviors:
|
|||
function (``field``) that instantiates this class, so if we were
|
||||
describing the stdlib dataclass behavior, we would provide the
|
||||
tuple argument ``(dataclasses.Field, dataclasses.field)``.
|
||||
* ``kwargs`` allows arbitrary additional keyword args to be passed to
|
||||
``dataclass_transform``. This gives type checkers the freedom to
|
||||
support experimental parameters without needing to wait for changes
|
||||
in ``typing.py``. Type checkers should report errors for any
|
||||
unrecognized parameters.
|
||||
|
||||
In the future, we may add additional parameters to
|
||||
``dataclass_transform`` as needed to support common behaviors in user
|
||||
|
@ -465,10 +471,10 @@ Runtime behavior
|
|||
----------------
|
||||
|
||||
At runtime, the ``dataclass_transform`` decorator's only effect is to
|
||||
set a string attribute named ``__dataclass_transform__`` on the
|
||||
decorated function or class to support introspection. The value of the
|
||||
attribute should be a dict mapping the names of the
|
||||
``dataclass_transform`` parameters to their values.
|
||||
set an attribute named ``__dataclass_transform__`` on the decorated
|
||||
function or class to support introspection. The value of the attribute
|
||||
should be a dict mapping the names of the ``dataclass_transform``
|
||||
parameters to their values.
|
||||
|
||||
For example:
|
||||
|
||||
|
@ -479,6 +485,7 @@ For example:
|
|||
"order_default": False,
|
||||
"kw_only_default": False,
|
||||
"field_specifiers": (),
|
||||
"kwargs": {}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue