-
-
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 2 commits
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 |
|---|---|---|
|
|
@@ -1972,6 +1972,7 @@ def _lazy_load_getattr_static(): | |
|
|
||
| _cleanups.append(_lazy_load_getattr_static.cache_clear) | ||
|
|
||
|
|
||
| def _pickle_psargs(psargs): | ||
| return ParamSpecArgs, (psargs.__origin__,) | ||
|
|
||
|
|
@@ -2483,10 +2484,9 @@ def get_type_hints(obj, globalns=None, localns=None, include_extras=False, | |
| if isinstance(obj, types.ModuleType): | ||
| globalns = obj.__dict__ | ||
| else: | ||
| nsobj = obj | ||
| # Find globalns for the unwrapped object. | ||
| while hasattr(nsobj, '__wrapped__'): | ||
| nsobj = nsobj.__wrapped__ | ||
| import inspect | ||
| nsobj = inspect.unwrap(obj) | ||
|
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. Everytime I see local imports for What I can suggest for this specific PR is to use If we switch to lazy imports, we'll also need to update the lazy import tests somewhere to check that
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. Maybe inspect.unwrap should live in functools instead, it's closely related to functools.wraps after all. But it's probably too late for that. Lazy importing sounds good to me. |
||
| globalns = getattr(nsobj, '__globals__', {}) | ||
| if localns is None: | ||
| localns = globalns | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Fix :func:`typing.get_type_hints` hanging indefinitely when a callable has a | ||
| circular ``__wrapped__`` chain (e.g. ``f.__wrapped__ = f``). A | ||
| :exc:`ValueError` is now raised on cycle detection, matching the behavior of | ||
| :func:`inspect.unwrap`. |
Uh oh!
There was an error while loading. Please reload this page.