[issue43893] typing.get_type_hints does not accept type annotations with leading whitespaces

Jarry Shaw report at bugs.python.org
Tue Sep 14 16:47:26 EDT 2021


Jarry Shaw <jarryshaw at icloud.com> added the comment:

Apparently static checkers like mypy doesn't rely on the `typing.get_type_hints` function to implement its type checking functions (as I had browsed through the code repo).

$ cat test.py
def foo(arg) -> ' str': ...
$ mypy test.py
Success: no issues found in 1 source file

If type checkers *think* this is acceptable, but the standard library doesn't, this can be some sort of inconsistency in my perspective.

As Saiyang Gou had suggested, I would rather prefer to change the behaviour of `compile` in `eval` mode to preserve the internal consistency of builtin functions and therefore to eliminate this *buggy* behaviour of `typing.get_type_hints`.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43893>
_______________________________________


More information about the Python-bugs-list mailing list