GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-146553: Fix infinite loop in typing.get_type_hints() on circular __wrapped__ by raminfp · Pull Request #146554 · python/cpython

Conversation

@raminfp

@raminfp raminfp commented Mar 28, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

#146553

  • Issue: Infinite Loop in typing.get_type_hints() via Circular __wrapped__ #146553

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@raminfp
gh-146553: Fix infinite loop in typing.get_type_hints() on circular _…
61a821b
…_wrapped__

#146553
@raminfp
raminfp requested review from AlexWaygood and JelleZijlstra as code owners March 28, 2026 08:16
@bedevere-app bedevere-app Bot mentioned this pull request Mar 28, 2026
Infinite Loop in typing.get_type_hints() via Circular __wrapped__ #146553
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Mar 28, 2026
brianschubert
brianschubert reviewed Mar 28, 2026
View reviewed changes

@brianschubert brianschubert left a comment

Copy link
Copy Markdown
Contributor

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.

I wonder if it would make sense to lazily import inspect here instead of having two implementations of essentially the same thing? inspect is a heavy import, but if you're calling get_type_hints you're already doing some sort of runtime signature introspection, in which case the import cost may be less of a concern.

@raminfp Please be mindful of https://devguide.python.org/getting-started/generative-ai/. I see you have been warned about relying on LLM generated PRs in the past. If you do decide to use LLMs, please make sure you take the time to scrutinize the output and compare it with the existing code before submitting a PR. In particular, you should try to match the style of the existing code (e.g. don't use _private_names for local variables).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

raminfp reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Lib/test/test_typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@raminfp
gh-146553: Use inspect.unwrap() for cycle detection instead of custom…
4e9afee
… helper
@raminfp

raminfp commented Mar 28, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@brianschubert Thank you for the review and for pointing this out. I do use LLM assistance when working on contributions (testing, security check, design and etc), but I wasn't sufficiently familiar with the relevant stdlib methods, specifically inspect.unwrap, which led to re-implementing logic that already exists. I appreciate the feedback, and I'll make sure to do a more thorough review of existing stdlib utilities before submitting patches in the future.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Mar 29, 2026
View reviewed changes
Comment thread Lib/typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/typing.py Outdated
Comment on lines +2488 to +2489
import inspect
nsobj = inspect.unwrap(obj)

@picnixz picnixz Mar 29, 2026

Copy link
Copy Markdown
Member

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.

Everytime I see local imports for inspect, I feel that we need to have a lower-level inspect utililty that can have less functions but more common to avoid having to import inspect.

What I can suggest for this specific PR is to use lazy import inspect instead at the top-level to make it a bit cleaner. For backports, we'll however need to use a local import. Note that we have other places with a local import to inspect, which you can eventually remove since we would have both a lazy and a local import (which would be redundant). I'll let @JelleZijlstra decide whether to want lazy imports.

If we switch to lazy imports, we'll also need to update the lazy import tests somewhere to check that inspect is lazily imported.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

raminfp reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@JelleZijlstra JelleZijlstra Mar 30, 2026

Copy link
Copy Markdown
Member

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.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@raminfp
gh-146553: Use _lazy_load_unwrap() helper instead of local import in …
e205384
…get_type_hints()
@raminfp
raminfp requested a review from picnixz March 30, 2026 08:24
picnixz
picnixz reviewed Mar 30, 2026
View reviewed changes
Comment thread Lib/typing.py Outdated
Comment on lines +1976 to +1984
@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)

@picnixz picnixz Mar 30, 2026

Copy link
Copy Markdown
Member

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.

I think we can just use lazy import inspect now and get rid of those lazy load stuff?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

raminfp reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@AlexWaygood AlexWaygood Mar 30, 2026

Copy link
Copy Markdown
Member

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@raminfp raminfp Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

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.

@picnixz Done, replaced both _lazy_load_getattr_static and _lazy_load_unwrap with a _LazyInspect class following the existing _LazyAnnotationLib pattern already in the file.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@picnixz picnixz Mar 30, 2026

Copy link
Copy Markdown
Member

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.

There was some controversy about using PEP 810 too widely in the stdlib

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@raminfp
gh-146553: Replace _lazy_load_* helpers with _LazyInspect for lazy in…
27c948d
…spect import
@raminfp
raminfp requested a review from picnixz March 30, 2026 08:45
picnixz
picnixz requested changes Mar 30, 2026
View reviewed changes
Comment thread Lib/typing.py
Comment on lines +175 to +182
class _LazyInspect:
def __getattr__(self, attr):
global _lazy_inspect
import inspect
_lazy_inspect = inspect
return getattr(inspect, attr)

_lazy_inspect = _LazyInspect()

@picnixz picnixz Mar 30, 2026

Copy link
Copy Markdown
Member

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.

Why do we have this construction? Please don't use an LLM to generate this. Just use lazy import inspect and check if there is nothing wrong with that construction as per the DPO thread.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@picnixz picnixz Mar 30, 2026

Copy link
Copy Markdown
Member

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.

For annotationlib, we'll clean it up either in a follow-up if codeowners do want it, or we will keep it as is until we need to modify annotationlib calls somewhere.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot removed the awaiting review label Mar 30, 2026
@bedevere-app

bedevere-app Bot commented Mar 30, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added the awaiting changes label Mar 30, 2026
@raminfp

raminfp commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

The intended fix (using inspect.unwrap()) is clear, but after several rounds of review I'm still uncertain about the exact lazy import pattern expected. The guidance "just use lazy import inspect" wasn't concrete enough for me to implement confidently, especially given the concerns raised about PEP 810 in the linked DPO thread.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@raminfp raminfp closed this Mar 30, 2026
@picnixz

picnixz commented Mar 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This is really like an LLM auto-reply. @raminfp The issues you report are worth my time as they are crash-related, but if you use an LLM to write your PRs without interacting with reviewers, it wastes both our time. In the future, please do notlet agents running in the background. Human interaction is necessary in a PR and if you do not want to follow those guidelines, I will not review your PRs anymore (and I have already warned you about this in the past).

StanFromIreland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@picnixz picnixz picnixz requested changes
@brianschubert brianschubert brianschubert left review comments
@JelleZijlstra JelleZijlstra Awaiting requested review from JelleZijlstra JelleZijlstra is a code owner
@AlexWaygood AlexWaygood Awaiting requested review from AlexWaygood AlexWaygood is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting changes

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@raminfp @picnixz @JelleZijlstra @brianschubert @AlexWaygood
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.