Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upHow to provide default value to StrictBool? #690
Comments
This comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
Makes sense. Although my instinct is that the need for |
This comment has been minimized.
This comment has been minimized.
Thanks for your responses! IMHO a stricter |
How can we provide a default value to a variable with type
StrictBool
in a way that is accepted by MyPy?