On 1/11/21 5:28 PM, Guido van Rossum wrote:
On Mon, Jan 11, 2021 at 5:21 PM Larry Hastings <la...@hastings.org
<mailto:la...@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/
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/IBBVD4KFZDEGBL2ISPJEARFGBPMWOLXG/
Code of Conduct: http://python.org/psf/codeofconduct/