Hi,
I found typing.get_type_hints()
raises a KeyError when the given class object has a wrong valued __module__
attribute (the value points non-existent module):
$ cat test.py
import typing
class Foo:
__module__ = 'unknown'
typing.get_type_hints(Foo)
$ python test.py
Traceback (most recent call last):
File "test.py", line 8, in <module>
typing.get_type_hints(Foo)
File "/Users/tkomiya/.pyenv/versions/3.8.3/lib/python3.8/typing.py", line 1223, in get_type_hints
base_globals = sys.modules[base.__module__].__dict__
KeyError: 'unknown'
I confirmed the error on python-3.8.3. Is this expected behavior? I guess it might be better to re-raise ValueError
instead. If so, I’ll post a bug report to bpo.
Additionally, I’d like to know what exceptions are typing.get_type_hints()
raised.