[issue41370] PEP 585 and ForwardRef

Niklas Rosenstein report at bugs.python.org
Tue Jan 25 15:19:15 EST 2022


Niklas Rosenstein <rosensteinniklas at gmail.com> added the comment:

It was not my intention to sound passive agressive. Thanks for providing the context around the time PEP 585 was discussed.

Frankly, I believe I have explained the problem quite well. But I would like to propose a solution.

I can't judge in what circumstance a `str` would end up in `typing._GenericAlias.__args__` since `typing._GenericAlias.__getitem__()` converts strings to `typing.ForwardRef` using `_type_check()` immediately.

Assuming this is indeed a case to be taken into account, I would propose that `typing.get_type_hint()` implements special treatment for `types.GenericAlias` such that strings in `__args__` are treated as forward references, and keep the old behaviour for `typing._GenericAlias`. Do you see any problems with that?

Of course this would break cases that have come to strictly expect strings in PEP 585 generic `__args__` since the release of Python 3.10 to stay strings, although I cannot come up with an example or think of a usecase myself.

----------

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


More information about the Python-bugs-list mailing list