-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Shouldn't typing.get_type_hints()
default globalns
to {}
instead of skipping base classes?
#88634
Comments
An issue was recently closed that caused synthetic classes and base classes with invalid https://bugs.python.org/issue41515 However, the implemented solution appears to be to skip those classes completely with a In order to work around this issue in my local install of Blender, I had to change 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: f350a26#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 |
Will, I think what you say makes sense. @guido / Ivan / Jelle What do you think? |
I agree with the OP, we can do better here. Ken, if you feel like it, a fix |
Yup. Will's proposal is to change the try-except to: base_globals = getattr(sys.modules.get(base.__module__, None), '__dict__', {}) @will, would you like to submit a PR for this? You'd need to sign a CLA. However, if you'd prefer I do it instead I'm happy to make the change. 3.10.0 beta 4 is releasing on 2021-07-10, so preferably we should get the change in by then. It's the last beta before the release candidates. |
I opened a PR with a fix and a couple comments on its method: I also *think* I signed the CLA correctly. Not sure. I used my login name here, rather than my Github login, but my account is linked. Didn't add any blurb/changelog notes. Would that be needed? Thanks for looking at this issue quickly! Let me know if there's anything else I can or should do. |
typing.get_type_hints()
, even with invalid.__module__
. #26862typing.get_type_hints()
, even with invalid.__module__
. (GH-26862) #26920Note: 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: