summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorEric V. Smith <ericvsmith@users.noreply.github.com>2022-05-02 16:36:39 (GMT)
committerGitHub <noreply@github.com>2022-05-02 16:36:39 (GMT)
commit5f9c0f5ddf441dedeb085b0d9f9c9488ca6bd44d (patch)
tree7cd849376052fc7278742ebeb799e77e35cd4793 /Doc
parent958f21c5cdb3bbbd16fec87164785cff3dacce96 (diff)
downloadcpython-5f9c0f5ddf441dedeb085b0d9f9c9488ca6bd44d.zip
cpython-5f9c0f5ddf441dedeb085b0d9f9c9488ca6bd44d.tar.gz
cpython-5f9c0f5ddf441dedeb085b0d9f9c9488ca6bd44d.tar.bz2
Add weakref_slot to dataclass decorator, to allow instances with slots to be weakref-able. (#92160)
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/dataclasses.rst17
1 files changed, 12 insertions, 5 deletions
diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst
index 08568da..ec50696 100644
--- a/Doc/library/dataclasses.rst
+++ b/Doc/library/dataclasses.rst
@@ -46,7 +46,7 @@ directly specified in the ``InventoryItem`` definition shown above.
Module contents
---------------
-.. decorator:: dataclass(*, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False)
+.. decorator:: dataclass(*, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False)
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 contents
class C:
...
- @dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False)
+ @dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False)
class C:
...
@@ -198,6 +198,13 @@ Module contents
base class ``__slots__`` may be any iterable, but *not* an iterator.
+ - ``weakref_slot``: If true (the default is ``False``), add a slot
+ named "__weakref__", which is required to make an instance
+ weakref-able. It is an error to specify ``weakref_slot=True``
+ without also specifying ``slots=True``.
+
+ .. versionadded:: 3.11
+
``field``\s may optionally specify a default value, using normal
Python syntax::
@@ -381,7 +388,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)
+.. 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)
Creates a new dataclass with name ``cls_name``, fields as defined
in ``fields``, base classes as given in ``bases``, and initialized
@@ -390,8 +397,8 @@ Module contents
or ``(name, type, Field)``. If just ``name`` is supplied,
``typing.Any`` is used for ``type``. The values of ``init``,
``repr``, ``eq``, ``order``, ``unsafe_hash``, ``frozen``,
- ``match_args``, ``kw_only``, and ``slots`` have the same meaning as
- they do in :func:`dataclass`.
+ ``match_args``, ``kw_only``, ``slots``, and ``weakref_slot`` 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