[issue35834] get_type_hints exposes an instance of ForwardRef (internal class) in its result, with `from __future__ import annotations` enabled

Ivan Levkivskyi report at bugs.python.org
Sun Jan 27 05:31:35 EST 2019


Ivan Levkivskyi <levkivskyi at gmail.com> added the comment:

It looks like an opposite side of https://github.com/python/typing/issues/508 (I wanted to work on it, but never had time to, sorry).

This question appeared couple times before, and I think there are pros and cons for both returning a ForwardRef() and for raising a NameError. So as I proposed in the issue above, there should be a flag to `get_type_hints()` that controls what to do (the name of the flag, and the default are of course debatable).

Of course, we should try to make `get_type_hints()` behave as much similar as possible with and without PEP 563, regardless. But my point is that currently we have this "in-between" behavior, and it is harder to maintain this "in-between" behavior against PEP 563, than two clearly defined extremes.

> So I expect that when calling get_type_hints it should return the unquoted string, rather than a ForwardReference.

I think the values in the returned dictionary should always be types, either fully evaluated, or ForwardRefs (expecting two options is easier than expecting three).

----------

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


More information about the Python-bugs-list mailing list