-
-
Notifications
You must be signed in to change notification settings - Fork 390
Open
Description
To make our to-json and from-json serialization type-safe, we need a class like this:
class Metadata(Generic[FromType, ToType]):
@classmethod
def from_json(cls, data: FromType) -> Self:
...
def to_json(self) -> ToType:
...This violates liskov because FromType gets narrower in subclasses. ToType and FromType effectively impose opposite variance requirements on Metadata here.
But it does work if we use generic protocols instead! So that's what we should do. I think it would be really nice to make all of our JSON serialization type-safe this way.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels