Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP 681: Add kwargs on dataclass_transform #2504

Merged
merged 1 commit into from
Apr 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions pep-0681.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:

Expand All @@ -479,6 +485,7 @@ For example:
"order_default": False,
"kw_only_default": False,
"field_specifiers": (),
"kwargs": {}
}


Expand Down