Message401590
This is my first issue on bugs.python.org, let me know if I can improve it in any way.
---
Originally reported and investigated here: https://github.com/mkdocstrings/mkdocstrings/issues/314
```
# final.py
from __future__ import annotations
from typing import Final, get_type_hints
name: Final[str] = "final"
class Class:
value: Final = 3000
get_type_hints(Class)
```
Run `python final.py`, and you'll get this traceback:
```
Traceback (most recent call last):
File "final.py", line 11, in <module>
get_type_hints(Class)
File "/.../lib/python3.8/typing.py", line 1232, in get_type_hints
value = _eval_type(value, base_globals, localns)
File "/.../lib/python3.8/typing.py", line 270, in _eval_type
return t._evaluate(globalns, localns)
File "/.../lib/python3.8/typing.py", line 517, in _evaluate
self.__forward_value__ = _type_check(
File "/.../lib/python3.8/typing.py", line 145, in _type_check
raise TypeError(f"Plain {arg} is not valid as type argument")
TypeError: Plain typing.Final is not valid as type argument
```
Now comment the `get_type_hints` call, launch a Python interpreter, and enter these commands:
>>> import final
>>> from typing import get_type_hints
>>> get_type_hints(final)
And you'll get this traceback:
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/.../lib/python3.9/typing.py", line 1449, in get_type_hints
value = _eval_type(value, globalns, localns)
File "/.../lib/python3.9/typing.py", line 283, in _eval_type
return t._evaluate(globalns, localns, recursive_guard)
File "/.../lib/python3.9/typing.py", line 538, in _evaluate
type_ =_type_check(
File "/.../lib/python3.9/typing.py", line 149, in _type_check
raise TypeError(f"{arg} is not valid as type argument")
TypeError: typing.Final[str] is not valid as type argument
```
I was able to replicate in 3.8, 3.9 and 3.10. The annotations future is not available in 3.7 or lower. Didn't try on 3.11. |
|
Date |
User |
Action |
Args |
2021-09-10 16:19:49 | pawamoy | set | recipients:
+ pawamoy |
2021-09-10 16:19:49 | pawamoy | set | messageid: <1631290789.33.0.47825654034.issue45166@roundup.psfhosted.org> |
2021-09-10 16:19:49 | pawamoy | link | issue45166 messages |
2021-09-10 16:19:49 | pawamoy | create | |
|