Skip to content

[3.15] gh-158936: Resolve lazy imports consistently for dataclass annotations (GH-158939) - #158946

Open
miss-islington wants to merge 1 commit into
python:3.15from
miss-islington:backport-0f1d4a7-3.15
Open

miss-islington wants to merge 1 commit into
python:3.15from
miss-islington:backport-0f1d4a7-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

With string annotations, dataclasses looks up the first name of each
annotation to detect ClassVar, InitVar and KW_ONLY. If that name was a
lazy import that could not be resolved, the lookup raised and the class
could not be created, while the same class works with non-string
annotations.

This resolves lazy imports the way annotationlib does: try to resolve
them, and treat a failure like a missing name.
(cherry picked from commit 0f1d4a7)

Co-authored-by: Brittany Reynoso [email protected]

…tations (pythonGH-158939)

With string annotations, dataclasses looks up the first name of each
annotation to detect ClassVar, InitVar and KW_ONLY. If that name was a
lazy import that could not be resolved, the lookup raised and the class
could not be created, while the same class works with non-string
annotations.

This resolves lazy imports the way annotationlib does: try to resolve
them, and treat a failure like a missing name.
(cherry picked from commit 0f1d4a7)

Co-authored-by: Brittany Reynoso <[email protected]>

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brittanyrey I'm thinking this can wait for 3.15.1, what do you think?

@brittanyrey

Copy link
Copy Markdown
Contributor

@JelleZijlstra that's my gut feeling.

@pablogsal what do you think?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants