diff options
author | Arie Bovenberg <a.c.bovenberg@gmail.com> | 2022-03-19 21:01:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-19 21:01:17 (GMT) |
commit | 82e9b0bb0ac44d4942b9e01b2cdd2ca85c17e563 (patch) | |
tree | c1cb2d3397dc3b907f8d19c7682a4703c4494d75 /Doc | |
parent | 383a3bec74f0bf0c1b1bef9e0048db389c618452 (diff) | |
download | cpython-82e9b0bb0ac44d4942b9e01b2cdd2ca85c17e563.zip cpython-82e9b0bb0ac44d4942b9e01b2cdd2ca85c17e563.tar.gz cpython-82e9b0bb0ac44d4942b9e01b2cdd2ca85c17e563.tar.bz2 |
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__.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/dataclasses.rst | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst index 0f6985f..08568da 100644 --- a/Doc/library/dataclasses.rst +++ b/Doc/library/dataclasses.rst @@ -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:: |