-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
How to provide default value to StrictBool? #690
Comments
Booleans are hard to deal with in a type-hinting context because python explicitly disallows subclassing The obvious choice would be to just use class Flags(BaseModel):
pretend: StrictBool = False # type: ignore but that may cause type checking issues since Another option is to put the from typing import TYPE_CHECKING
from pydantic import BaseModel
if TYPE_CHECKING:
StrictBool = bool
else:
from pydantic import StrictBool
class Flags(BaseModel):
pretend: StrictBool = False This should behave properly with type checking, but is a little uglier everywhere you import it. @samuelcolvin Do you think it could make sense to just put the above alias for |
Makes sense. Although my instinct is that the need for |
Thanks for your responses! IMHO a stricter |
…er only if strict check is enabled (pydantic#690)
How can we provide a default value to a variable with type
StrictBool
in a way that is accepted by MyPy?The text was updated successfully, but these errors were encountered: