Message380803
FWIW here's a minimal demo:
from __future__ import annotations
from typing import get_type_hints
class C:
def func(self, a: "C"):
pass
print(get_type_hints(func))
In 3.8 this prints
{'a': ForwardRef('C')}
while in 3.9 it raises NameError:
Traceback (most recent call last):
File "C:\Users\gvanrossum\cpython\t.py", line 4, in <module>
class C:
File "C:\Users\gvanrossum\cpython\t.py", line 8, in C
print(get_type_hints(func))
File "C:\Python39\lib\typing.py", line 1386, in get_type_hints
value = _eval_type(value, globalns, localns)
File "C:\Python39\lib\typing.py", line 254, in _eval_type
return t._evaluate(globalns, localns, recursive_guard)
File "C:\Python39\lib\typing.py", line 497, in _evaluate
self.__forward_value__ = _eval_type(
File "C:\Python39\lib\typing.py", line 254, in _eval_type
return t._evaluate(globalns, localns, recursive_guard)
File "C:\Python39\lib\typing.py", line 493, in _evaluate
eval(self.__forward_code__, globalns, localns),
File "<string>", line 1, in <module>
NameError: name 'C' is not defined |
|
Date |
User |
Action |
Args |
2020-11-12 04:15:28 | gvanrossum | set | recipients:
+ gvanrossum, glyph, ethan smith, BTaskaya, mental, ryansobol |
2020-11-12 04:15:28 | gvanrossum | set | messageid: <1605154528.14.0.198852137408.issue41987@roundup.psfhosted.org> |
2020-11-12 04:15:28 | gvanrossum | link | issue41987 messages |
2020-11-12 04:15:28 | gvanrossum | create | |
|