[Python-Dev] Re: Let's Fix Class Annotations -- And Maybe Annotations Generally

2021年1月11日 17:55:06 -0800

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

Reply via email to