Repository navigation
gh-160665: Recognize dataclass markers deferred by lazy imports - #160668
Open
LarryHu0217 wants to merge 3 commits into
Open
LarryHu0217 wants to merge 3 commits into
LarryHu0217 wants to merge 3 commits into
Conversation
Resolve the complete circular from-import before defining A so lazy_imports=all exercises unresolved annotations as in normal mode. Keep the strict ForwardRef and classification assertions unchanged.
Contributor
|
|
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.
Preserve partially resolved annotations when a lazy import cannot be resolved. In
annotationlib'sFORWARDREFformat, resolve lazy imports on name lookup and treat a failed resolution like an undefined name. This keeps known outer types such aslist,InitVarandClassVarintact, with aForwardReffor the unresolved inner name.Remove the dataclasses annotation-prefix workaround from the earlier revision. Keep the circular-import regressions for direct, qualified and aliased
InitVar,ClassVarand ordinary deferred fields. TheInitVarassertions now verify an actualInitVarholding the innerForwardRef.Add direct annotationlib regressions for module, class and function annotations, nested containers, successful lazy imports, undefined names and explicit ForwardRef evaluation with globals or locals. Check that VALUE-format errors and STRING-format output remain unchanged, and that an unused lazy import is not loaded. Update the Library NEWS entry.
Validation on macOS arm64 with the existing CPython 3.16.0a1+dev debug interpreter built at
dc28c3a358221b1e0ae5f926b72e112cbd1d03f7:test_dataclasses,test_annotationlib,test_typing,test_lazy_importandtest_inspect, with--fail-env-changed -u cpu, strict warning/bytes flags and ignored Python environment variables: all five succeed in both normal mode and-X lazy_imports=all; each run reports 1,711 tests and one skip.-R 3:3succeeds in both modes, with no positive leaks in the three measured repetitions.The annotationlib and dataclasses sources and their owning test files match main
32fe0cca23d9e9677107abe4d701cb20768c7926checked before committing. Tests used an isolated sparse worktree and a source-path overlay for the existing interpreter. Patchcheck only had its source-directory selection pointed to that worktree. Related suites ran at the cached validation baseline; later native changes, the entire CPython suite, native Windows, the documentation build and full hook runner were not validated locally. Ruff retains its Python 3.15 support warning; the hook pins 0.15.17. An initial Ruff attempt omitted the original stdlib configuration from the sparse worktree; materializing that exact configuration resolved the unrelated diagnostics without changing rules or sources.This addresses unresolved lazy imports, not general missing attributes on eagerly imported, partially initialized modules. No fetch, dependency installation, new environment or native build was performed for this revision.