Message399662
> 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? |
|
Date |
User |
Action |
Args |
2021-08-16 17:45:54 | kj | set | recipients:
+ kj, gvanrossum, mhils |
2021-08-16 17:45:54 | kj | set | messageid: <1629135954.97.0.748767519097.issue44926@roundup.psfhosted.org> |
2021-08-16 17:45:54 | kj | link | issue44926 messages |
2021-08-16 17:45:54 | kj | create | |
|