This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kj
Recipients gvanrossum, kj, mhils
Date 2021-08-16.17:45:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1629135954.97.0.748767519097.issue44926@roundup.psfhosted.org>
In-reply-to
Content
> 1. func1 doesn't crash, but also doesn't resolve the forward reference. I am not sure if this expected behavior.

Good observation! That's indeed the current behavior. The reason is a little subtle - list[...] is using a special builtin type (https://docs.python.org/3/library/stdtypes.html#types-genericalias), while typing.List is the one from typing. The typing version wraps all strings in ForwardRef(), while the builtin version shouldn't import from typing, so it doesn't have that luxury. get_type_hints could probably support the builtin version, though I'd imagine we'd need some rework.

Re: 2. You're right there too. Storing the defined module in __forward_module__ is an interesting proposal.

For your specific use case (where the user is using Python 3.6), you could pass in globalns and localns to get_type_hints as a temporary workaround. Off the top of my head:
get_type_hints(func2, globalns=foo.__dict__) might work. Would that work for your library?
History
Date User Action Args
2021-08-16 17:45:54kjsetrecipients: + kj, gvanrossum, mhils
2021-08-16 17:45:54kjsetmessageid: <1629135954.97.0.748767519097.issue44926@roundup.psfhosted.org>
2021-08-16 17:45:54kjlinkissue44926 messages
2021-08-16 17:45:54kjcreate