Skip to content

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

Merged
JelleZijlstra merged 1 commit into
python:3.15from
miss-islington:backport-0f1d4a7-3.15
Oct 9, 2026
Merged

JelleZijlstra merged 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 breynoso@meta.com

…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 <breynoso@meta.com>

@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?

@brittanyrey

Copy link
Copy Markdown
Contributor

@JelleZijlstra Spoke to Pablo offline, he agrees we should add this in 3.15.1.

@JelleZijlstra
JelleZijlstra merged commit 00cf7d9 into python:3.15 Oct 9, 2026
59 checks passed
@miss-islington
miss-islington deleted the backport-0f1d4a7-3.15 branch October 9, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants