3 ms·
huh. i will fix that, thanks. there should be a @checked annotation on the function that is checked in the example there. pyptyp is pretty comprehensive. fo
by andrewcooke 14y ago
huh. i will fix that, thanks. there should be a @checked annotation on the function that is checked in the example there.
pyptyp is pretty comprehensive. for example, Rec(a=Seq(Opt(int)),b=Alt(float,str)) is the type for something like a dict where a is a list that contains ints or None and b is either a float or a string.
BUT it's pure python so it's not at all fast. i wouldn't use type checking throughout a codebase - only for debugging, or tests.
it's perhaps more useful as a start for building other things. for example, it includes mapping from JSON to python objects - it can use type annotations to guide the construction of python objects from JSON lists and maps. but on the other hand the internals are quite complex (i have been working with it recently, after not using it for a year or so, and it's taken some effort to understand everything).
- reinhardt 14y agoAnother similar project: https://github.com/podio/valideer https://github.com/podio/valideer. The (rough) equivalent schema for the example above can be expressed as {"a": ["?integer"], "b": AnyOf("number", "string")}.
- andrewcooke 14y agoalso, i should perhaps mention, compared to some other libraries, pytyp is integrated with ABCs and the Python type system. so you can use isinstance() with these expressions, for example.