Ken Jin <kenjin4...@gmail.com> added the comment:
> 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? ---------- nosy: +gvanrossum, kj _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44926> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com