On 1/11/21 5:28 PM, Guido van Rossum wrote:
On Mon, Jan 11, 2021 at 5:21 PM Larry Hastings <larry@hastings.org> wrote:
Slots intelligently support inheritance, too.  I always kind of wondered why annotations didn't support inheritance--if D is a subclass of C, why doesn't D.__annotations__ contain all C's annotations too?  But we're way past reconsidering that behavior now.

Anyway, `__slots__` doesn't behave that way -- seems it behaves similar to `__annotations__`.

__slots__ itself doesn't behave that way, but subclasses do inherit the slots defined on their parent:

class C:
    __slots__ = ['a']

class D(C):
    __slots__ = ['b']

d = D()
d.a = 5
d.b = "foo"
print(f"{d.a=} {d.b=}")

prints

d.a=5 d.b='foo'

That's the inheritance behavior I was referring to.


Cheers,


/arry