Skip to content

refactor!: Share one struct builder across parser steps, allow ClassVar and InitVar in dataclass and attrs specs - #154

Merged
FBruzzesi merged 4 commits into
mainfrom
refactor/adapters-structs
Nov 22, 2026
Merged

FBruzzesi merged 4 commits into
mainfrom
refactor/adapters-structs

Conversation

@FBruzzesi

Copy link
Copy Markdown
Owner

Summary

  • ClassVar and InitVar no longer crash dataclass and attrs specs: the check that catches an undecorated subclass treated every annotation as a field, so counter: ClassVar[int] = 0 raised. Both adapters now share one check that skips these pseudo-fields (bare or subscripted).
  • One struct builder: nested dataclasses, TypedDicts, attrs classes and Pydantic models are now built by a single parse_struct in parsers/_base.py, replacing four near-identical methods. The TypedDict path now goes through typed_dict_adapter like the others.
  • No more error-hiding fallbacks: the except Exception around get_type_hints in attrs_adapter and the TypedDict parser is gone. A local attrs class with an unresolvable annotation now raises the real NameError instead of a misleading "could not handle type" error, matching the dataclass path.
  • Duplicate names in a sequence spec raise: [("a", int), ("a", str)] used to keep only the last a without telling you.

Breaking changes

  • An undecorated subclass of a dataclass or attrs class now raises TypeError instead of AssertionError. The message is unchanged.
  • A sequence spec with repeated field names now raises ValueError listing the repeated names.

@FBruzzesi
FBruzzesi merged commit e1f1557 into main Nov 22, 2026
13 checks passed
@FBruzzesi
FBruzzesi deleted the refactor/adapters-structs branch November 22, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant