Fix TimedeltaConverter allowing negative values by default (#6354)

Co-authored-by: zephyrkul <zephyrkul@users.noreply.github.com>
This commit is contained in:
Zephyrkul 2024-04-20 16:17:38 -05:00 committed by GitHub
parent 00e41d38f9
commit 11ebd40dfa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -334,6 +334,7 @@ else:
If provided, any parsed value higher than this will raise an exception
minimum : Optional[datetime.timedelta]
If provided, any parsed value lower than this will raise an exception
Defaults to 0 seconds, pass None explicitly to allow negative values
allowed_units : Optional[List[str]]
If provided, you can constrain a user to expressing the amount of time
in specific units. The units you can choose to provide are the same as the
@ -344,7 +345,14 @@ else:
apply.
"""
def __init__(self, *, minimum=None, maximum=None, allowed_units=None, default_unit=None):
def __init__(
self,
*,
minimum=timedelta(seconds=0),
maximum=None,
allowed_units=None,
default_unit=None,
):
self.allowed_units = allowed_units
self.default_unit = default_unit
self.minimum = minimum
@ -372,7 +380,7 @@ if TYPE_CHECKING:
*,
default_unit: Optional[str] = None,
maximum: Optional[timedelta] = None,
minimum: Optional[timedelta] = None,
minimum: Optional[timedelta] = timedelta(seconds=0),
allowed_units: Optional[List[str]] = None,
) -> Type[timedelta]:
...
@ -383,7 +391,7 @@ else:
*,
default_unit: Optional[str] = None,
maximum: Optional[timedelta] = None,
minimum: Optional[timedelta] = None,
minimum: Optional[timedelta] = timedelta(seconds=0),
allowed_units: Optional[List[str]] = None,
) -> Type[timedelta]:
"""
@ -398,6 +406,7 @@ else:
If provided, any parsed value higher than this will raise an exception
minimum : Optional[datetime.timedelta]
If provided, any parsed value lower than this will raise an exception
Defaults to 0 seconds, pass None explicitly to allow negative values
allowed_units : Optional[List[str]]
If provided, you can constrain a user to expressing the amount of time
in specific units. The units you can choose to provide are the same as the