-
-
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
… helper
- Loading branch information
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,20 +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. | ||
| # Use an id-based visited set to detect and break on cycles in the | ||
| # __wrapped__ chain (e.g. f.__wrapped__ = f), matching the behavior | ||
| # of inspect.unwrap(). | ||
| _seen_ids = {id(nsobj)} | ||
| while hasattr(nsobj, '__wrapped__'): | ||
| nsobj = nsobj.__wrapped__ | ||
| _nsobj_id = id(nsobj) | ||
| if _nsobj_id in _seen_ids: | ||
| raise ValueError( | ||
| f'wrapper loop when unwrapping {obj!r}' | ||
| ) | ||
| _seen_ids.add(_nsobj_id) | ||
| 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 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.