diff options
author | Victorien <65306057+Viicos@users.noreply.github.com> | 2024-10-01 13:51:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-01 13:51:51 (GMT) |
commit | 3e3a4d231518f91ff2f3c5a085b3849e32f1d548 (patch) | |
tree | ecfd11282bd45f28f4acca136db8acab61385de2 /Doc | |
parent | 91e64be731fe42e6b252b95d79d900251388bfc6 (diff) | |
download | cpython-3e3a4d231518f91ff2f3c5a085b3849e32f1d548.zip cpython-3e3a4d231518f91ff2f3c5a085b3849e32f1d548.tar.gz cpython-3e3a4d231518f91ff2f3c5a085b3849e32f1d548.tar.bz2 |
gh-118974: Add `decorator` argument to `make_dataclass` (gh-122723)
This is to allow the `dataclasses.make_dataclass` infrastructure to be used with another decorator that's compliant with `typing.dataclass_transform`. The new `decorator` argument to `dataclasses.make_dataclass` is `dataclasses.dataclass`, which used to be hard coded.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/dataclasses.rst | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst index 51c1a42..e34b2db 100644 --- a/Doc/library/dataclasses.rst +++ b/Doc/library/dataclasses.rst @@ -399,7 +399,7 @@ Module contents :func:`!astuple` raises :exc:`TypeError` if *obj* is not a dataclass instance. -.. function:: make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False, module=None) +.. function:: make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False, module=None, decorator=dataclass) Creates a new dataclass with name *cls_name*, fields as defined in *fields*, base classes as given in *bases*, and initialized @@ -415,6 +415,11 @@ Module contents of the dataclass is set to that value. By default, it is set to the module name of the caller. + The *decorator* parameter is a callable that will be used to create the dataclass. + It should take the class object as a first argument and the same keyword arguments + as :func:`@dataclass <dataclass>`. By default, the :func:`@dataclass <dataclass>` + function is used. + This function is not strictly required, because any Python mechanism for creating a new class with :attr:`!__annotations__` can then apply the :func:`@dataclass <dataclass>` function to convert that class to @@ -438,6 +443,9 @@ Module contents def add_one(self): return self.x + 1 + .. versionadded:: 3.14 + Added the *decorator* parameter. + .. function:: replace(obj, /, **changes) Creates a new object of the same type as *obj*, replacing |