Behaviour of Partial
for objects with nullable types
#613
Replies: 2 comments
-
There is another side to the issue as well. As we make all the types This is what I think we need for a proper
I think this can be solved by using a sentinel that is not a valid json type. It would be breaking, but I'm not sure how useful the current implementation is with these limitations anyway. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
TypedDict
anddataclass
have a slight difference in behavior when used withPartial
. Omitted properties are excluded forTypedDict
, while fordataclass
they are set toNone
.{}
{"a":null,"b":null,"c":null}
{"c": null}
{"a":null,"b":null,"c":null}
{}
{}
{"c": null}
{"c": null}
The
TypedDict
behavior is advantageous as can discern when a nullable property has been explicitly set to null or not. However, a dataclass instance cannot be constructed without values for all attributes, so maybe some sort of sentinel default value is necessary for that case.Beta Was this translation helpful? Give feedback.
All reactions