Repository navigation
refactor!: Share one struct builder across parser steps, allow ClassVar and InitVar in dataclass and attrs specs - #154
Merged
Conversation
…instead of keeping the last one
…s specs, raise `TypeError` for undecorated subclasses
…p the error-hiding `get_type_hints` fallbacks
…the dataclass test runs on Python 3.10
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.
Summary
ClassVarandInitVarno longer crash dataclass and attrs specs: the check that catches an undecorated subclass treated every annotation as a field, socounter: ClassVar[int] = 0raised. Both adapters now share one check that skips these pseudo-fields (bare or subscripted).parse_structinparsers/_base.py, replacing four near-identical methods. The TypedDict path now goes throughtyped_dict_adapterlike the others.except Exceptionaroundget_type_hintsinattrs_adapterand the TypedDict parser is gone. A local attrs class with an unresolvable annotation now raises the realNameErrorinstead of a misleading "could not handle type" error, matching the dataclass path.[("a", int), ("a", str)]used to keep only the lastawithout telling you.Breaking changes
TypeErrorinstead ofAssertionError. The message is unchanged.ValueErrorlisting the repeated names.