Skip to content

Commit

Permalink
Fix potential API compatibility issue in parse_timedelta() (Cog-Creat…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackenmen authored Apr 20, 2024
1 parent 11ebd40 commit e61327a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions redbot/core/commands/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def parse_timedelta(
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
Defaults to 0 seconds, pass `datetime.timedelta.min` 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 chose to provide are the same as the
Expand All @@ -135,6 +135,10 @@ def parse_timedelta(
"minutes",
"seconds",
]
if minimum is None:
minimum = timedelta(seconds=0)
if maximum is None:
maximum = timedelta.max
params = _parse_and_match(argument, allowed_units)
if params:
try:
Expand All @@ -143,13 +147,13 @@ def parse_timedelta(
raise BadArgument(
_("The time set is way too high, consider setting something reasonable.")
)
if maximum and maximum < delta:
if maximum < delta:
raise BadArgument(
_(
"This amount of time is too large for this command. (Maximum: {maximum})"
).format(maximum=humanize_timedelta(timedelta=maximum))
)
if minimum and delta < minimum:
if delta < minimum:
raise BadArgument(
_(
"This amount of time is too small for this command. (Minimum: {minimum})"
Expand Down Expand Up @@ -334,7 +338,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
Defaults to 0 seconds, pass `datetime.timedelta.min` 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 Expand Up @@ -406,7 +410,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
Defaults to 0 seconds, pass `datetime.timedelta.min` 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 e61327a

Please sign in to comment.