New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typing.get_type_hints generates KeyError #85687
Comments
Windows 10 Pro 64 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' |
Hm, the fix would seem simple enough. Can you submit a PR? It would be nice if it had a test as well. |
I guess more libraries will experience this with |
This change introduced a regression: $ ./python -m test test___all__
0:00:00 load avg: 0.28 Run tests sequentially
0:00:00 load avg: 0.28 [1/1] test___all__
test test___all__ failed -- Traceback (most recent call last):
File "/home/vstinner/python/master/Lib/test/test___all__.py", line 104, in test_all
self.check_all(modname)
File "/home/vstinner/python/master/Lib/test/test___all__.py", line 25, in check_all
exec("import %s" % modname, names)
File "/home/vstinner/python/master/Lib/contextlib.py", line 140, in __exit__
next(self.gen)
File "/home/vstinner/python/master/Lib/test/support/warnings_helper.py", line 177, in _filterwarnings
raise AssertionError("unhandled warning %s" % reraise[0])
AssertionError: unhandled warning {message : SyntaxWarning('assertion is always true, perhaps remove parentheses?'), category : 'SyntaxWarning', filename : '/home/vstinner/python/master/Lib/test/test_typing.py', lineno : 2275, line : None} test___all__ failed == Tests result: FAILURE == 1 test failed: Total duration: 2.7 sec It comes from the following line of test_bad_module() in Lib/test/test_typing:
assert should be used as "assert test" or "assert test, expr". assert (expr, expr) tests if the tuple (2 items) is true, and it's always true. |
Thanks -- odd this didn't fail in CI. We'll get it fixed. |
The CI runs tests with "make buildbottest" which uses the -w option: -w, --verbose2 re-run failed tests in verbose mode When test___all__ is re-run in verbose mode, it doesn't fail: "== Tests result: FAILURE then SUCCESS ==" |
Thanks Victor. I have created #25379 that uses self.assertEqual instead of assert that produces syntax warning. |
I see that all PRs are merged, and the CI issue is fixed as well. I close the issue. commit eb77133
|
typing.get_type_hints()
, even with invalid.__module__
. #26862Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: