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-156924: Try reifying lazy imports in `ForwarRef.evaluate()` by Viicos · Pull Request #156940 · python/cpython

Conversation

@Viicos

@Viicos Viicos commented Sep 4, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor
  • Issue: Lazy imports and resolving type hints #156924

Sorry, something went wrong.

Uh oh!

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

All reactions
@Viicos
pythongh-156924: Try reifying lazy imports in ForwarRef.evaluate()
8754d32
@Viicos
Viicos requested a review from JelleZijlstra as a code owner September 4, 2026 14:23
@bedevere-app bedevere-app Bot mentioned this pull request Sep 4, 2026
Lazy imports and resolving type hints #156924
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Sep 4, 2026
JelleZijlstra
JelleZijlstra reviewed Sep 4, 2026
View reviewed changes
Comment thread Lib/annotationlib.py Resolved

Uh oh!

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

@JelleZijlstra JelleZijlstra added the needs backport to 3.15 bugs and security fixes label Sep 4, 2026
@Viicos @JelleZijlstra
Update Lib/annotationlib.py
a490405
Co-authored-by: Jelle Zijlstra <[email protected]>
@DavidCEllis

DavidCEllis commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

This looks right to me, and it also now correctly resolves lazy imports that would succeed if the annotations would fail for a different reason (other than a missing name):

from annotationlib import get_annotations, Format

lazy from typing import Any

class Example:
    a: object.fail
    b: Any

annos = get_annotations(Example, format=Format.FORWARDREF)
print(annos['b'])

Before:

<lazy_import 'typing.Any'>

With this PR:

typing.Any
All reactions

Sorry, something went wrong.

Uh oh!

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

@JelleZijlstra

JelleZijlstra commented Sep 7, 2026

Copy link
Copy Markdown
Member

@Viicos could you add a unit test for the case @DavidCEllis brings up?

All reactions

Sorry, something went wrong.

Uh oh!

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

@Viicos
Add extra test
7e4ffa8
JelleZijlstra
JelleZijlstra approved these changes Sep 7, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Sep 7, 2026
johnslavik
johnslavik approved these changes Sep 7, 2026
View reviewed changes
johnslavik
johnslavik reviewed Sep 7, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2026-09-04-14-15-31.gh-issue-156924.3Ux7IJ.rst Resolved

Uh oh!

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

@Viicos Viicos mentioned this pull request Sep 8, 2026
Add support for lazy imports pydantic/pydantic#13776
Merged
5 tasks
@encukou @johnslavik
Link LazyImportType in NEWS
51cdab4
Co-authored-by: Bartosz Sławecki <[email protected]>
@JelleZijlstra
JelleZijlstra merged commit 52ffffe into python:main Sep 9, 2026
51 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label Sep 9, 2026
@miss-islington-app

miss-islington-app Bot commented Sep 9, 2026

Copy link
Copy Markdown

Thanks @Viicos for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app

bedevere-app Bot commented Sep 9, 2026

Copy link
Copy Markdown

GH-157224 is a backport of this pull request to the 3.15 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Sep 9, 2026
hugovk pushed a commit that referenced this pull request Sep 10, 2026
@miss-islington @Viicos
@JelleZijlstra @encukou @johnslavik
[3.15] gh-156924: Try reifying lazy imports in ForwarRef.evaluate() (…
013c4ae
…GH-156940) (#157224)

Co-authored-by: Victorien <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Bartosz Sławecki <[email protected]>
maurycy added a commit to maurycy/cpython that referenced this pull request Sep 10, 2026
@maurycy
Merge branch 'main' into tachyon-native-callable
e028ff5
* main: (158 commits)
  pythongh-156924: Try reifying lazy imports in `ForwarRef.evaluate()` (python#156940)
  pythongh-156233: Fix typos and code snippet errors in the docs (python#156475)
  pythongh-156837: Refer to yield expressions in generator function definitions (pythonGH-156863)
  pythongh-155292: Skip updating unicodedata with mismatched interpreter (pythonGH-157066)
  pythongh-157170: Document the scope of global curses settings (pythonGH-157207)
  pythongh-155966: Correct handling of `math.tanpi` poles (python#155980)
  pythongh-157170: Restore use_env() after test_use_prescr_screen in test_curses (pythonGH-157171)
  pythongh-156910: fix deadlock in type_set_abstractmethods under free-threading (python#156948)
  pythongh-155648: Write the empty and placeholder IDLE tests (python#156260)
  pythongh-153569: centralize formatted-string state and source spans (python#156484)
  pythongh-157137: Mark the PEP 820 soft deprecations as 3.15, not `next` (python#157138)
  pythongh-152433: Use regular LoadLibrary in UWP for Windows system libs (pythonGH-156972)
  pythongh-121617: Fix Py_CLEAR() memcpy in C++: replace NULL with _Py_NULL (python#157188)
  pythongh-157135: Fix documentation errors in the `math.atan{2}pi` functions (python#157136)
  pythongh-121617: Fix Py_CLEAR() in C++: replace NULL with _Py_NULL (python#157067)
  pythongh-156774: Speed up pdb startup with asyncio guard (python#156775)
  pythongh-156109: Allow static, non-framework iOS builds (python#156110)
  pythongh-156780: Emscripten: add missing EM_JS_DEPS (python#156798)
  pythongh-152936: Make privileged functions available on Android (python#152977)
  pythongh-123018: Keep the libedit history file header when truncating (pythonGH-157165)
  ...
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
@Viicos @JelleZijlstra
@encukou @johnslavik @clin1234
pythongh-156924: Try reifying lazy imports in ForwarRef.evaluate() (p…
fc345e3
…ython#156940)

Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Bartosz Sławecki <[email protected]>
johnslavik added a commit to johnslavik/cpython that referenced this pull request Sep 14, 2026
@Viicos @JelleZijlstra
@encukou @johnslavik
pythongh-156924: Try reifying lazy imports in ForwarRef.evaluate() (p…
5c64994
…ython#156940)

Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Bartosz Sławecki <[email protected]>
@destopianpirate destopianpirate mentioned this pull request Oct 4, 2026
Remove xfail on lazy imports tests pydantic/pydantic#13930
Merged
Kronuz pushed a commit to Kronuz/cpython that referenced this pull request Oct 5, 2026
@miss-islington @Viicos
@JelleZijlstra @encukou @johnslavik @Kronuz
[3.15] pythongh-156924: Try reifying lazy imports in `ForwarRef.evalu…
7263e28
…ate()` (pythonGH-156940) (python#157224)

Co-authored-by: Victorien <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Bartosz Sławecki <[email protected]>
(cherry picked from commit 013c4ae)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@johnslavik johnslavik johnslavik approved these changes
@JelleZijlstra JelleZijlstra JelleZijlstra approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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

@Viicos @DavidCEllis @JelleZijlstra @johnslavik @encukou
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 01402503 — 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.