Skip to content

gh-156924: Try reifying lazy imports in ForwarRef.evaluate() - #156940

Open
Viicos wants to merge 2 commits into
python:mainfrom
Viicos:vp/forwardref-reify
Open

gh-156924: Try reifying lazy imports in ForwarRef.evaluate()#156940
Viicos wants to merge 2 commits into
python:mainfrom
Viicos:vp/forwardref-reify

Conversation

@Viicos

@Viicos Viicos commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Comment thread Lib/annotationlib.py Outdated
@JelleZijlstra JelleZijlstra added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Sep 4, 2026
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@DavidCEllis

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

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

Labels

awaiting review needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants