mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-46382 dataclass(slots=True) now takes inherited slots into account (GH-31980)
Do not include any members in __slots__ that are already in a base class's __slots__.
This commit is contained in:
parent
383a3bec74
commit
82e9b0bb0a
4 changed files with 77 additions and 9 deletions
|
@ -188,6 +188,16 @@ Module contents
|
|||
|
||||
.. versionadded:: 3.10
|
||||
|
||||
.. versionchanged:: 3.11
|
||||
If a field name is already included in the ``__slots__``
|
||||
of a base class, it will not be included in the generated ``__slots__``
|
||||
to prevent `overriding them <https://docs.python.org/3/reference/datamodel.html#notes-on-using-slots>`_.
|
||||
Therefore, do not use ``__slots__`` to retrieve the field names of a
|
||||
dataclass. Use :func:`fields` instead.
|
||||
To be able to determine inherited slots,
|
||||
base class ``__slots__`` may be any iterable, but *not* an iterator.
|
||||
|
||||
|
||||
``field``\s may optionally specify a default value, using normal
|
||||
Python syntax::
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue