-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Truthy/Falsey Type #197
Comments
Using This makes the behavior inconsistent between |
I think the behaviour is currently correct for TruthyType = Literal[True, 1, '1', 'on', 't', 'true', 'y', 'yes']
FalseyType = Literal[False, 1, '0', 'off', 'f', 'false', 'n', 'no'] But having something in pydantic (or maybe pydantic_extra_types) would be extremely useful. |
Feel free to add something to |
@sydney-runkle, do you think |
I think we should stick to how literals are handled in Pydantic, just bc this would be a breaking change and I think |
Initial Checks
Description
We have a situation where we'd like to validate against a string, or some truthy value. We thought we could do:
from typing import Literal
from pydantic import TypeAdapter
However we get an error with
x.validate_python("True")
, as this seems to (correctly) validate only against the valueTrue
.What would be great for pydantic to provide is a type we could use which would accept all truthy/falsey values, like a type of
bool
would. For example:Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: