Message390661
I think we can just skip evaluating annotations for complex targets when in module or class scope (they are not stored anyway). The point of PEP 563 is to suppress any evaluation of annotations (regardless of position) at definition time, while type checkers can still analyze them as usual.
This is the current behavior (ever since 3.7, with `from __future__ import annotations`):
Python 3.10.0a7 (default, Apr 6 2021, 17:59:12) [GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 1
>>> x.y: print('evaluated in module')
evaluated in module
>>> class A:
... u = 2
... u.v: print('evaluated in class')
...
evaluated in class
And I think they should become no-ops at run-time (as if the annotations were wrapped in string form). |
|
Date |
User |
Action |
Args |
2021-04-09 20:01:31 | gousaiyang | set | recipients:
+ gousaiyang, gvanrossum, serhiy.storchaka, lys.nikolaou, pablogsal, BTaskaya |
2021-04-09 20:01:31 | gousaiyang | set | messageid: <1617998491.22.0.531822600912.issue42737@roundup.psfhosted.org> |
2021-04-09 20:01:31 | gousaiyang | link | issue42737 messages |
2021-04-09 20:01:31 | gousaiyang | create | |
|