Skip to content

Commit c67a649

Browse files
hynekTinche
andcommitted
Explain that slotted classes don't support multiple inheritance
Fixes #667 Co-authored-by: Tin Tvrtković <[email protected]>
1 parent b02335f commit c67a649

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

docs/glossary.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ Glossary
1010
This is the type of class you get by default both with and without ``attrs``.
1111

1212
slotted classes
13-
A class that has no ``__dict__`` attribute and `defines <https://docs.python.org/3/reference/datamodel.html#slots>`_ its attributes in a ``__slots__`` attribute instead.
14-
In ``attrs``, they are created by passing ``slots=True`` to ``@attr.s``.
13+
A class whose instances have no ``__dict__`` attribute and `define <https://docs.python.org/3/reference/datamodel.html#slots>`_ their attributes in a ``__slots__`` attribute instead.
14+
In ``attrs``, they are created by passing ``slots=True`` to ``@attr.s`` (and are on by default in `attr.define`/`attr.mutable`/`attr.frozen`.
15+
1516

1617
Their main advantage is that they use less memory on CPython [#pypy]_.
1718

@@ -36,6 +37,8 @@ Glossary
3637
- Slotted classes can inherit from other classes just like non-slotted classes, but some of the benefits of slotted classes are lost if you do that.
3738
If you must inherit from other classes, try to inherit only from other slotted classes.
3839

40+
- However, `it's not possible <https://docs.python.org/3/reference/datamodel.html#notes-on-using-slots>`_ to inherit from more than one class that has attributes in ``__slots__`` (you will get an ``TypeError: multiple bases have instance lay-out conflict``).
41+
3942
- Slotted classes must implement :meth:`__getstate__ <object.__getstate__>` and :meth:`__setstate__ <object.__setstate__>` to be serializable with `pickle` protocol 0 and 1.
4043
Therefore, ``attrs`` creates these methods automatically for ``slots=True`` classes (Python 2 uses protocol 0 by default).
4144

0 commit comments

Comments
 (0)