You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Preserve legacy asdict semantics for values outside the fast paths
The single-pass walker replaced dataclasses.asdict, but a lot of
compatibility behavior lived inside asdict rather than in the conversion
pass that followed it: container subclasses were rebuilt through their
own constructors, mapping keys were recursed, namedtuples and defaultdict
were special-cased, and every leaf was deep-copied. Walking values in
place silently dropped all of that.
Restrict the inline fast paths to exact built-in types, where walking in
place is provably identical to what asdict produced, and hand every other
value back to the real asdict via a throwaway box dataclass. Delegating
rather than reimplementing matters because those internals have shifted
between releases and this package supports 3.10 through 3.14.
Also remove the tuple branch added earlier. Normalizing datetimes inside
tuples is a real bug fix, but a user-visible one, so it does not belong
in a performance change. Tuples now route to the compatibility path and
come back exactly as they did before, quirk included.
Bound the field-name cache with functools.lru_cache so dynamically
created dataclass types cannot pin an unbounded number of entries. It
measures identically to the unbounded dict (0.0204s vs 0.0206s per 200k
lookups) while dropping the cache entirely is 9.4x slower, so the cache
stays but is now capped.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6322dc7f-81ee-4d42-be2d-cef84cf62d15
0 commit comments