Repository navigation
[3.15] gh-158936: Resolve lazy imports consistently for dataclass annotations (GH-158939) - #158946
Open
miss-islington wants to merge 1 commit into
Open
miss-islington wants to merge 1 commit into
miss-islington wants to merge 1 commit into
Conversation
…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
approved these changes
Oct 7, 2026
JelleZijlstra
left a comment
Member
There was a problem hiding this comment.
@brittanyrey I'm thinking this can wait for 3.15.1, what do you think?
Contributor
|
@JelleZijlstra that's my gut feeling. @pablogsal what do you think? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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]