[Python-Dev] Re: PEP: Deferred Evaluation Of Annotations Using Descriptors

2021-01-16 Thread Inada Naoki
This PEP doesn't cover about what happened when __co_annotation__() failed (e.g. NameError). Forward reference is a major reason, but not a only reason for using string annotation. There are two other reasons: * Avoid importing heavy module. * Avoid circular imports. In these cases, this

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

2021-01-16 Thread Larry Hastings
On 1/16/21 4:09 PM, Greg Ewing wrote: On 17/01/21 12:31 pm, Larry Hastings wrote: Consider the best practice for getting class annotations, example here from Lib/dataclasses.py:     cls_annotations = cls.__dict__.get('__annotations__', {}) Isn't that going to get broken anyway? It won't

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

2021-01-16 Thread Greg Ewing
On 17/01/21 12:31 pm, Larry Hastings wrote: Consider the best practice for getting class annotations, example here from Lib/dataclasses.py: cls_annotations = cls.__dict__.get('__annotations__', {}) Isn't that going to get broken anyway? It won't trigger the calling of

[Python-Dev] Re: PEP: Deferred Evaluation Of Annotations Using Descriptors

2021-01-16 Thread Larry Hastings
Given your comments below, I'd summarize the semantics you want as: Looking up names for annotations should work exactly as it does today with "stock" semantics, except annotations should also see names that haven't been declared yet. Thus an annotation should be able to see names set

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

2021-01-16 Thread Larry Hastings
On 1/16/21 8:41 AM, Nick Coghlan wrote: Could you get the best of both worlds by making __annotations__ an auto-populating descriptor on "type", the way it is on functions? Continue to add a non-empty annotations dict to the class dict eagerly, but only add the empty dict when

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

2021-01-16 Thread Nick Coghlan
On Wed, 13 Jan 2021, 12:35 pm Larry Hastings, wrote: > > On 1/12/21 5:28 PM, Brett Cannon wrote: > > The other thing to keep in mind is we are talking about every module, > class, and function getting 64 bytes ... which I bet isn't that much. > > Actually it's only every module and class.

[Python-Dev] Re: __init_subclass__ and metaclasses

2021-01-16 Thread Nick Coghlan
On Tue, 12 Jan 2021, 11:55 am Ethan Furman, wrote: > On 1/7/21 4:56 AM, Nick Coghlan wrote: > > > Both EnumMeta and ABCMeta should probably be relying on `__set_name__` > > for their per-member set up work these days, rather than deferring > > that work until after __new__ returns. > > And