-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-146553: Fix infinite loop in typing.get_type_hints() on circular __wrapped__ #146554
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
Changes from 1 commit
61a821b
4e9afee
e205384
27c948d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1973,6 +1973,17 @@ def _lazy_load_getattr_static(): | |
| _cleanups.append(_lazy_load_getattr_static.cache_clear) | ||
|
|
||
|
|
||
| @functools.cache | ||
| def _lazy_load_unwrap(): | ||
| # Import unwrap lazily so as not to slow down the import of typing.py | ||
| # Cache the result so we don't slow down get_type_hints() unnecessarily | ||
| from inspect import unwrap | ||
| return unwrap | ||
|
|
||
|
|
||
| _cleanups.append(_lazy_load_unwrap.cache_clear) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can just use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was some controversy about using PEP 810 too widely in the stdlib https://discuss.python.org/t/concerns-about-x-lazy-imports-none/106203 I don't have a strong opinion myself, to be clear
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @picnixz Done, replaced both
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Jelle said he was fine so I think we can do the switch unless it's breaking something. @raminfp please check that the concerns expressed in the DPO thread are not concerns, but do so without using an LLM. |
||
|
|
||
|
|
||
| def _pickle_psargs(psargs): | ||
| return ParamSpecArgs, (psargs.__origin__,) | ||
|
|
||
|
|
@@ -2485,8 +2496,7 @@ def get_type_hints(obj, globalns=None, localns=None, include_extras=False, | |
| globalns = obj.__dict__ | ||
| else: | ||
| # Find globalns for the unwrapped object. | ||
| import inspect | ||
| nsobj = inspect.unwrap(obj) | ||
| nsobj = _lazy_load_unwrap()(obj) | ||
| globalns = getattr(nsobj, '__globals__', {}) | ||
| if localns is None: | ||
| localns = globalns | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.