3 ms·
Thought people might find this amusing / interesting (wish I had written it for April 1... although it does work). It's a spin-off from the use of type annotat
by andrewcooke 16y ago
Thought people might find this amusing / interesting (wish I had written it for April 1... although it does work). It's a spin-off from the use of type annotations to guide the interpretation of JSON data (Pytyp will marshal JSON/YAML data into Python classes, which is useful if you're using JSON to talk to some kind of service).
[Edit: Optional, product and sum types are supported, along with simple polymorphism. There's currently no type variables and no dispatch by type - although I think both could be added]
- masklinn 16y agoIt's really cool that optional, product and sum types are supported. Does it work correctly with abstract base classes as well? (I'm expecting yes, just checking). Could it work with structural types as well? That would strike me as "more pythonic", and I've always been surprised that no Python type-annotation scheme can handle structural specs (though abcs are a step in the right direction).
- andrewcooke 16y agoThanks. I assume it works with ABCs, but haven't actually tried it (I ran out of time and wanted to publish something as a first release this weekend). Structural types would make more sense for general use, but not for what the larger library was actually intended for (I think) so I never really looked in that direction (and I don't have any ideas on how to extend it to include them, either). I do have an idea for a kind of type matching across sum types which will be quite neat if it works...