-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix serialization of dataclasses without __slots__
The optimization of serializing the __dict__ attribute of dataclass instances without __slots__ assumes that __dict__ containing K is a necessary and sufficient condition of the dataclass having a non-pseudo field named K. However, this does not hold when the dataclass contains - a field defined with init=False and a default value - a field with a descriptor object as default value - a cached property This commit fixes the serialization in the above cases by changing the code so that the __dict__ attribute is only used to get a field value, falling back to checking the field type and getting the value with PyObject_GetAttr if the value is not in __dict__. The price for correctness is a ~20% slowdown. Signed-off-by: Emanuele Giaquinta <[email protected]>
- Loading branch information
Showing
2 changed files
with
105 additions
and
76 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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