[New-bugs-announce] [issue41515] typing.get_type_hints generates KeyError

Eric Fahlgren report at bugs.python.org
Mon Aug 10 09:43:58 EDT 2020

New submission from Eric Fahlgren <ericfahlgren at gmail.com>:

Windows 10 Pro 64
Python 3.8.3 64
wxPython 4.1.0

It appears that there are synthetic classes in the mro, which don't appear in the type's namespace, raising KeyError when encountered.  From reading the function's doc and source, it looks like it should handle this internally and return a valid dict (possibly empty), and not raise KeyError.

>>> import typing, wx
>>> typing.get_type_hints(wx.Window)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Program Files\Python38\lib\typing.py", line 1223, in get_type_hints
    base_globals = sys.modules[base.__module__].__dict__

>>> wx.Window.mro()
[<class 'wx._core.Window'>, <class 'wx._core.WindowBase'>, <class 'wx._core.EvtHandler'>, <class 'wx._core.Object'>, <class 'wx._core.Trackable'>, <class 'sip.wrapper'>, <class 'sip.simplewrapper'>, <class 'object'>]

KeyError: 'sip'

components: Library (Lib)
messages: 375111
nosy: eric.fahlgren
priority: normal
severity: normal
status: open
title: typing.get_type_hints generates KeyError
versions: Python 3.8

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list