Replies: 3 comments 7 replies
-
Re
|
Beta Was this translation helpful? Give feedback.
-
I’m curious as to what the advantage of a zod like API is versus Pydantic? Pydantic V2 will be able to do non-record types, something like: from typing import Annotated
from pydantic import Gt, validate, parse
myint = Annotated[int, Gt(0)]
assert validate(myint, 1) == 1
assert parse(myint, “1”) == 1
validate(myint, -1) # error
parse(myint, “foo”) #error (the parse and validate functions are hypothetical but plauisible) |
Beta Was this translation helpful? Give feedback.
-
Context: zod.dev
Zod is TypeScript library that does two things well:
I've implemented the parsing of data part in python
But I can't decide whether the typing inference is possible or if it's just a dead end?
Example from typescript
The benefit of the inference is that we can use our schemas as type information
I feel like this should be possible in Python but beyond simple types like str, int, optional I get lost in the lack of features in python typing
Here's a quick implementation for string in python
Optional is similar
We can even do things like Record (or Mapping I guess)
But then we get to things like ZodUnion and I'm lost 🤷
And then there is ZodLiteral - there's no way to infer a literal value from a generic variable since there's no such thing as
LiteralVar
.Am I just hitting the edge of what python typing is capable of?
The ultimate goal would be to be able to do things like
As well as
Beta Was this translation helpful? Give feedback.
All reactions