Re:Loading Pydantic models from JSON without running out of ...
by itamarst on Thursday May 22, 2025 @03:10PM
(#44065613)
You can't add extra attributes that weren't part of the original dataclass definition:
Most of the time this is not a thing you actually need to do.
[ Parent
| on HN ]
Re:Loading Pydantic models from JSON without running out of ...
by masklinn on Thursday May 22, 2025 @04:05PM
(#44066271)
Also some of the introspection stops working e.g. vars().
If you're using dataclasses it's less of an issue because dataclasses.asdict.
Re:Loading Pydantic models from JSON without running out of ...
by monomial on Thursday May 22, 2025 @04:36PM
(#44066640)
I rarely need to dynamically add attributes myself on dataclasses like this but unfortunately this also means things like `@cached_property` won't work because it can't internally cache the method result anywhere.
Re:Loading Pydantic models from JSON without running out of ...
by franga2000 on Friday May 23, 2025 @02:38AM
(#44070478)
IIRC you can just include a __dict__ slot and @cached_property should start working again. I