-
Notifications
You must be signed in to change notification settings - Fork 283
Closed
python/cpython
#6824Description
I know there are plans to make all type annotations strings eventually. So I was playing around and discovered this problem.
import typing
class Good:
foo: typing.ClassVar[int] = 7
print(typing.get_type_hints(Good))
class Bad:
foo: 'typing.ClassVar[int]' = 7
typing.get_type_hints(Bad)
{'foo': typing.ClassVar[int]}
Traceback (most recent call last):
File "classvar_problem.py", line 10, in <module>
typing.get_type_hints(Bad)
File "/usr/local/homebrew/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/typing.py", line 1511, in get_type_hints
value = _eval_type(value, base_globals, localns)
File "/usr/local/homebrew/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/typing.py", line 350, in _eval_type
return t._eval_type(globalns, localns)
File "/usr/local/homebrew/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/typing.py", line 246, in _eval_type
"Forward references must evaluate to types.")
File "/usr/local/homebrew/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/typing.py", line 374, in _type_check
raise TypeError(msg + " Got %.100r." % (arg,))
TypeError: Forward references must evaluate to types. Got typing.ClassVar[int].
Metadata
Metadata
Assignees
Labels
No labels