-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
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
base: main
Are you sure you want to change the base?
Changes from all commits
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) | ||
|
Comment on lines
+2488
to
+2489
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 |
||
| 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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this change. Diffs should not change unrelated parts of the code as they are then less readable.