Skip to content

Commit

Permalink
Fix TimedeltaConverter allowing negative values by default (#6354)
Browse files Browse the repository at this point in the history
Co-authored-by: zephyrkul <[email protected]>
  • Loading branch information
Zephyrkul and Zephyrkul authored Apr 20, 2024
1 parent 00e41d3 commit 11ebd40
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions redbot/core/commands/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ class TimedeltaConverter(dpy_commands.Converter):
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
Expand All @@ -344,7 +345,14 @@ class TimedeltaConverter(dpy_commands.Converter):
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
Expand Down Expand Up @@ -372,7 +380,7 @@ def get_timedelta_converter(
*,
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]:
...
Expand All @@ -383,7 +391,7 @@ def get_timedelta_converter(
*,
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]:
"""
Expand All @@ -398,6 +406,7 @@ def get_timedelta_converter(
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
Expand Down

0 comments on commit 11ebd40

Please sign in to comment.