summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorEric V. Smith <ericvsmith@users.noreply.github.com>2021-04-11 01:28:42 (GMT)
committerGitHub <noreply@github.com>2021-04-11 01:28:42 (GMT)
commit750f484752763fe9ac1d6455780aabcb67f25508 (patch)
tree263bacbb75386ab2bf327bcbc7bfcc949140efd6 /Doc
parentc3a478b7e56b92bcd980b7ded34005f8b339602e (diff)
downloadcpython-750f484752763fe9ac1d6455780aabcb67f25508.zip
cpython-750f484752763fe9ac1d6455780aabcb67f25508.tar.gz
cpython-750f484752763fe9ac1d6455780aabcb67f25508.tar.bz2
bpo-43764: Add match_args=False parameter to dataclass decorator and to make_dataclasses function. (GH-25337)
Add match_args=False parameter to dataclass decorator and to make_dataclass function.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/dataclasses.rst19
1 files changed, 14 insertions, 5 deletions
diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst
index 133cc0a..0c0c7a8 100644
--- a/Doc/library/dataclasses.rst
+++ b/Doc/library/dataclasses.rst
@@ -46,7 +46,7 @@ directly specified in the ``InventoryItem`` definition shown above.
Module-level decorators, classes, and functions
-----------------------------------------------
-.. decorator:: dataclass(*, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False)
+.. decorator:: dataclass(*, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True)
This function is a :term:`decorator` that is used to add generated
:term:`special method`\s to classes, as described below.
@@ -79,7 +79,7 @@ Module-level decorators, classes, and functions
class C:
...
- @dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False)
+ @dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True)
class C:
...
@@ -161,6 +161,14 @@ Module-level decorators, classes, and functions
:meth:`__setattr__` or :meth:`__delattr__` is defined in the class, then
:exc:`TypeError` is raised. See the discussion below.
+ - ``match_args``: If true (the default is ``True``), the
+ ``__match_args__`` tuple will be created from the list of
+ parameters to the generated :meth:`__init__` method (even if
+ :meth:`__init__` is not generated, see above). If false, or if
+ ``__match_args__`` is already defined in the class, then
+ ``__match_args__`` will not be generated.
+
+
``field``\s may optionally specify a default value, using normal
Python syntax::
@@ -325,7 +333,7 @@ Module-level decorators, classes, and functions
Raises :exc:`TypeError` if ``instance`` 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)
+.. 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)
Creates a new dataclass with name ``cls_name``, fields as defined
in ``fields``, base classes as given in ``bases``, and initialized
@@ -333,8 +341,9 @@ Module-level decorators, classes, and functions
iterable whose elements are each either ``name``, ``(name, type)``,
or ``(name, type, Field)``. If just ``name`` is supplied,
``typing.Any`` is used for ``type``. The values of ``init``,
- ``repr``, ``eq``, ``order``, ``unsafe_hash``, and ``frozen`` have
- the same meaning as they do in :func:`dataclass`.
+ ``repr``, ``eq``, ``order``, ``unsafe_hash``, ``frozen``, and
+ ``match_args`` have the same meaning as they do in
+ :func:`dataclass`.
This function is not strictly required, because any Python
mechanism for creating a new class with ``__annotations__`` can