From b92cb7f230d584eb32e7064952aa27003e00f606 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 7 Apr 2025 16:07:54 +0300 Subject: [PATCH 1/2] gh-132221: Fix `__match_args__` generation docs in `dataclasses.rst` --- Doc/library/dataclasses.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst index f63a01e9570791..a0957400ea768d 100644 --- a/Doc/library/dataclasses.rst +++ b/Doc/library/dataclasses.rst @@ -164,7 +164,7 @@ Module contents - *match_args*: If true (the default is ``True``), the :attr:`~object.__match_args__` tuple will be created from the list of - parameters to the generated :meth:`~object.__init__` method (even if + non kw-only parameters to the generated :meth:`~object.__init__` method (even if :meth:`!__init__` is not generated, see above). If false, or if :attr:`!__match_args__` is already defined in the class, then :attr:`!__match_args__` will not be generated. From 31a129bf539ed82323653a40cfbd26f3d1087b71 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 7 Apr 2025 17:06:32 +0300 Subject: [PATCH 2/2] More docs --- Doc/library/dataclasses.rst | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst index a0957400ea768d..0bc171da4eefc7 100644 --- a/Doc/library/dataclasses.rst +++ b/Doc/library/dataclasses.rst @@ -164,7 +164,7 @@ Module contents - *match_args*: If true (the default is ``True``), the :attr:`~object.__match_args__` tuple will be created from the list of - non kw-only parameters to the generated :meth:`~object.__init__` method (even if + non keyword-only parameters to the generated :meth:`~object.__init__` method (even if :meth:`!__init__` is not generated, see above). If false, or if :attr:`!__match_args__` is already defined in the class, then :attr:`!__match_args__` will not be generated. @@ -175,11 +175,12 @@ Module contents fields will be marked as keyword-only. If a field is marked as keyword-only, then the only effect is that the :meth:`~object.__init__` parameter generated from a keyword-only field must be specified - with a keyword when :meth:`!__init__` is called. There is no - effect on any other aspect of dataclasses. See the - :term:`parameter` glossary entry for details. Also see the + with a keyword when :meth:`!__init__` is called. See the :term:`parameter` + glossary entry for details. Also see the :const:`KW_ONLY` section. + Keyword-only fields are not included in :attr:`!__match_args__`. + .. versionadded:: 3.10 - *slots*: If true (the default is ``False``), :attr:`~object.__slots__` attribute @@ -299,6 +300,8 @@ Module contents This is used when the generated :meth:`~object.__init__` method's parameters are computed. + Keyword-only fields are also not included in :attr:`!__match_args__`. + .. versionadded:: 3.10 - ``doc``: optional docstring for this field.