FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-158936: Resolve lazy imports consistently for dataclass annotations by brittanyrey · Pull Request #158939 · python/cpython · GitHub

Repository navigation

gh-158936: Resolve lazy imports consistently for dataclass annotations - #158939

Merged
JelleZijlstra merged 1 commit into
python:mainfrom
brittanyrey:b-dataclass-lazy-annotation
Oct 7, 2026
Merged

JelleZijlstra merged 1 commit into
python:mainfrom
brittanyrey:b-dataclass-lazy-annotation

Conversation

brittanyrey commented Oct 6, 2026 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

Before this change, dataclasses would handle the failure case for lazily imported annotations differently based on if that annotation was materialized as a string or an object. For objects, imports that could not be materialized were ignored, but for strings the errors would bubble up and completely prevent the initialization of the dataclass.

After this change, string annotations will resolve lazy imports the same way that annotationlib does: try to resolve them, and treat a failure as a missing annotation.

… like annotationlib

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.
JelleZijlstra added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Oct 7, 2026
JelleZijlstra merged commit 0f1d4a7 into python:main Oct 7, 2026
60 checks passed

Copy link
Copy Markdown

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

bedevere-app Bot commented Oct 7, 2026

Copy link
Copy Markdown

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

bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Oct 7, 2026
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL