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:
Arie Bovenberg 2022-03-19 22:01:17 +01:00 committed by GitHub
parent 383a3bec74
commit 82e9b0bb0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 9 deletions

View file

@ -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::