[Python-Dev] Re: Proto-PEP part 1: Forward declaration of classes

2022年4月25日 20:34:51 -0700

The forward class annotations would not need need to be processed at runtime 
and could be no-ops. 
forward class A:
 x: int
 y: list[int]
A.__annotations__ could be empty. For a more complete example you could have,
forward class A:
 value: B # This annotation is solely for type checker and is not actually 
saved at runtime.
class B:
 value: A # Real annotation that is saved.
continue class A:
 value: B # Real annotation that is saved.
The rule would then be that any annotation inside forward class is equivalent 
to a noop. Continue class would still need to have same annotation repeated to 
actually set it at runtime.
_______________________________________________
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/O3HMCIWUM6NGTSCGL7HFRBSDT7A4KFHP/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to