[issue44468] Shouldn't `typing.get_type_hints()` default `globalns` to `{}` instead of skipping base classes?

2021-06-20 Thread Will Chen

New submission from Will Chen :

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.

--
messages: 396205
nosy: willchencontact
priority: normal
severity: normal
status: open
title: Shouldn't `typing.get_type_hints()` default `globalns` to `{}` instead 
of skipping base classes?
type: behavior
versions: Python 3.10, Python 3.11

___
Python tracker 
<https://bugs.python.org/issue44468>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44468] Shouldn't `typing.get_type_hints()` default `globalns` to `{}` instead of skipping base classes?

2021-06-22 Thread Will Chen


Change by Will Chen :


--
keywords: +patch
pull_requests: +25437
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26862

___
Python tracker 
<https://bugs.python.org/issue44468>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44468] Shouldn't `typing.get_type_hints()` default `globalns` to `{}` instead of skipping base classes?

2021-06-22 Thread Will Chen


Will Chen  added the comment:

I opened a PR with a fix and a couple comments on its method:

https://github.com/python/cpython/pull/26862

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.

--

___
Python tracker 
<https://bugs.python.org/issue44468>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41515] typing.get_type_hints generates KeyError

2021-06-23 Thread Will Chen


Change by Will Chen :


--
nosy: +WCA
nosy_count: 6.0 -> 7.0
pull_requests: +25458
pull_request: https://github.com/python/cpython/pull/26862

___
Python tracker 
<https://bugs.python.org/issue41515>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com