This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author WCA
Recipients WCA
Date 2021-06-21.04:11:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1624248699.71.0.0674887100793.issue44468@roundup.psfhosted.org>
In-reply-to
Content
An issue was recently closed that caused synthetic classes and base classes with invalid `__module__` attributes to raise `KeyError()` in `typing.get_type_hints()`:

https://bugs.python.org/issue41515

However, the implemented solution appears to be to skip those classes completely with a `continue` statement, instead of getting the annotations that may still be present by using an empty globals dictonary:

https://github.com/python/cpython/pull/25352/files#diff-ddb987fca5f5df0c9a2f5521ed687919d70bb3d64eaeb8021f98833a2a716887

In order to work around this issue in my local install of Blender, I had to change `.get_type_hints()` to use an empty dictionary for `globalns` when encountering invalid modules, rather than skipping them:

https://developer.blender.org/T88986#1179812

From reading the commit where the broken behaviour was first introduced— Which was described/designed as "backwards compatible"— It looks like the original behaviour was also to use an empty dictionary, and never skip:

https://github.com/python/cpython/commit/f350a268a7071ce7d7a5bb86a9b1229782d4963b#diff-ddb987fca5f5df0c9a2f5521ed687919d70bb3d64eaeb8021f98833a2a716887R1501

Using an empty dictionary also seemed to be mentioned in the bug report linked above.

IMO using an empty dictionary and still returning annotations from classes with invalid modules seems like it'd be more sensible, predictable, and backwards-compatible, while skipping base classes is likely to just replace the obvious `KeyError()` with less reproducible and nastier errors caused by returning incomplete type hints.
History
Date User Action Args
2021-06-21 04:11:39WCAsetrecipients: + WCA
2021-06-21 04:11:39WCAsetmessageid: <1624248699.71.0.0674887100793.issue44468@roundup.psfhosted.org>
2021-06-21 04:11:39WCAlinkissue44468 messages
2021-06-21 04:11:39WCAcreate