Validation and data conversion using Pydantic #12142
Unanswered
adam-arold
asked this question in
Question
Replies: 1 comment
-
This is a limitation of the Several limitations exist:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've been using Pydantic to create models that I use for input validation / data cleaning. These work properly when a framework calls the constructor (like Flask) but if I call the constructor by hand I get type errors because I'm not passing the "final" types into it. For example here I have a model that has
Decimal
attributes:but when I'm trying to write a test for this the linter complains because I'm passing
str
s, and notDecimal
s (even though the actual code runs fine):The linter error I get is
Is there a way to modify the constructor that Pydantic generates to include this conversion function (
validate_order_decimals
)? Alternatively, is there some other libarary that has similar functionality and supports this? I'm coming from Typescript and I've used zod, schema, and other similar libraries that support this, so I'm pretty sure this exists in Python too.Beta Was this translation helpful? Give feedback.
All reactions