Repository navigation
Resolve forward references nested in other annotations - #827
Open
Aschenbath wants to merge 1 commit into
Open
Aschenbath wants to merge 1 commit into
Aschenbath wants to merge 1 commit into
Conversation
This was referenced Nov 4, 2026
This branch has not been deployed
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 #201.
Without PEP 563, a quoted forward reference nested in another annotation — like
y: Optional["Y"]in a mutually recursive pair of attrs classes — survived into dispatch and failed withStructureHandlerNotFoundError: Unsupported type: ForwardRef('Y'), while the same code worked withfrom __future__ import annotations.adapted_fieldsonly triggered type resolution when a field's type was a plain string (the PEP 563 shape). It now uses a small_contains_forward_refhelper that also detectsForwardRefs nested inside typing constructs (viaget_args), for both attrs classes and dataclasses, and resolves the class's types in that case (attrs.resolve_types/get_type_hintsrespectively).Tests:
test_structure_quoted_forward_refstotests/test_structure.pywith the issue's mutually recursive example.tests/test_structure.py,tests/test_recursive.py,tests/test_gen_dict.py,tests/test_dicts.py(141 passed);tests/test_gen_dict_563.py,tests/test_tuples_563.py,tests/test_generics.py,tests/test_generics_649.py,tests/test_generics_nested.py,tests/test_baseconverter.py,tests/test_typeddicts.py,tests/test_preconf.py(183 passed, 20 skipped; 2 pre-existingtest_tomllib_converter*failures also occur on unmodified upstreammainin this environment).ruff checkandruff formaton the changed files: pass.A changelog entry is included in
HISTORY.md.