Repository navigation
gh-160665: Recognize dataclass markers deferred by lazy imports - #160668
Open
LarryHu0217 wants to merge 1 commit into
Open
LarryHu0217 wants to merge 1 commit into
LarryHu0217 wants to merge 1 commit into
Conversation
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.
Fixes #160665.
When an unresolved lazy import causes annotation evaluation to fall back to a
ForwardReffor the entire expression, annotations such asInitVar[A]are currently treated as ordinary dataclass fields. Reuse the existing annotation-prefix resolver for this representation.This restores argument forwarding to
__post_init__and keeps affectedClassVarannotations out of instance fields. The originalField.typeand ordinary deferred fields are preserved.Adds deterministic circular-import fixtures covering direct, qualified and aliased
InitVar, aClassVarcase and an ordinary deferred-field control, plus a Library NEWS entry.Validation on macOS arm64 using the existing
--with-pydebuginterpreter built atdc28c3a358221b1e0ae5f926b72e112cbd1d03f7(CPython 3.16.0a1+dev):__post_init__-argument error before the fix.dataclasses.py, the regression has threeInitVarsubcase errors and oneClassVarassertion failure; the ordinary deferred-field control passes. All five subcases pass after the fix../python.exe -B -m test -u cpu --timeout 600 test_dataclasses test_annotationlib test_typing test_lazy_import test_inspect: all five suites succeed; reported run=1,708, skipped=1../python.exe -B -m test -R 3:3 -m test_lazy_import_forwardref_annotations test_dataclasses: success, with no positive leaks in the three measured repetitions.Tools/patchcheck/patchcheck.py, scopedruff check --no-fix --no-cacheon the four changed Python files,git diff --cached --checkandgit diff --check: pass.Ruff was the existing 0.15.22 binary, with its Python-3.15-support warning retained. The hook pins 0.15.17; the full hook runner was not installed or run. An initial attempt with another installed Ruff 0.14.6 could not parse the repository's Python 3.15 target configuration; the successful check used 0.15.22 without changing that configuration.
The dataclasses source and complete owning test tree, annotationlib source/tests, typing source/tests, inspect source and lazy-import test tree match main checked at
2468c35c3b3375fe0745fa5b5429d47098ebb45e. That main is 28 commits ahead of the validation baseline; the compared test-support change concerns sanitizer configuration detection. Later native changes and the entire CPython test suite were not validated locally. No new native build or dependency installation was performed.