From ae31029cbb800bfecba7a7633a36d25da75dcf94 Mon Sep 17 00:00:00 2001 From: Evan Purkhiser Date: Wed, 30 Oct 2024 16:24:02 -0400 Subject: [PATCH] black: Format raise calls Adjusted a few of these to not use explicit string concatenation. I did leave one or two that were egregiously long otherwise. This is also using line length 119 now. --- src/croniter/croniter.py | 51 +++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/croniter/croniter.py b/src/croniter/croniter.py index eb8b6aa..5533434 100644 --- a/src/croniter/croniter.py +++ b/src/croniter/croniter.py @@ -290,15 +290,11 @@ def _alphaconv(cls, index, key, expressions): try: return cls.ALPHACONV[index][key] except KeyError: - raise CroniterNotAlphaError( - "[{0}] is not acceptable".format(" ".join(expressions)) - ) + raise CroniterNotAlphaError("[{0}] is not acceptable".format(" ".join(expressions))) def get_next(self, ret_type=None, start_time=None, update_current=True): if start_time and self._expand_from_start_time: - raise ValueError( - "start_time is not supported when using expand_from_start_time = True." - ) + raise ValueError("start_time is not supported when using expand_from_start_time = True.") return self._get_next( ret_type=ret_type, start_time=start_time, @@ -382,8 +378,7 @@ def _get_next( ret_type = ret_type or self._ret_type if not issubclass(ret_type, (float, datetime.datetime)): - raise TypeError("Invalid ret_type, only 'float' or 'datetime' " - "is acceptable.") + raise TypeError("Invalid ret_type, only 'float' or 'datetime' is acceptable.") # exception to support day of month and day of week as defined in cron dom_dow_exception_processed = False @@ -879,9 +874,7 @@ def _expand( expressions = efl.split() if len(expressions) not in VALID_LEN_EXPRESSION: - raise CroniterBadCronError( - "Exactly 5, 6 or 7 columns has to be specified for iterator expression." - ) + raise CroniterBadCronError("Exactly 5, 6 or 7 columns has to be specified for iterator expression.") if len(expressions) > UNIX_CRON_LEN and second_at_beginning: # move second to it's own(6th) field to process by same logical @@ -903,13 +896,13 @@ def _expand( if "?" in expr: if expr != "?": raise CroniterBadCronError( - "[{0}] is not acceptable. Question mark can not " - "used with other characters".format(expr_format) + "[{0}] is not acceptable. Question mark can not used with other characters".format(expr_format) ) if field_index not in [DAY_FIELD, DOW_FIELD]: raise CroniterBadCronError( - "[{0}] is not acceptable. Question mark can only used " - "in day_of_month or day_of_week".format(expr_format) + "[{0}] is not acceptable. Question mark can only used in day_of_month or day_of_week".format( + expr_format + ) ) # currently just trade `?` as `*` expr = "*" @@ -934,8 +927,10 @@ def _expand( assert nth >= 1 and nth <= 5 except (KeyError, ValueError, AssertionError): raise CroniterBadCronError( - "[{0}] is not acceptable. Invalid day_of_week " - "value: '{1}'".format(expr_format, nth)) + "[{0}] is not acceptable. Invalid day_of_week value: '{1}'".format( + expr_format, nth + ) + ) elif last: e = last nth = g["pre"] # 'l' @@ -980,9 +975,7 @@ def _expand( # normally, it's already guarded by the RE that should not accept not-int values. if not only_int_re.search(str(step)): raise CroniterBadCronError( - "[{0}] step '{2}' in field {1} is not acceptable".format( - expr_format, field_index, step - ) + "[{0}] step '{2}' in field {1} is not acceptable".format(expr_format, field_index, step) ) step = int(step) @@ -1057,10 +1050,9 @@ def _expand( e_list += [a for a in rng if a not in e_list] else: if t.startswith("-"): - raise CroniterBadCronError(( - "[{0}] is not acceptable," - "negative numbers not allowed" - ).format(expr_format)) + raise CroniterBadCronError( + "[{0}] is not acceptable," "negative numbers not allowed".format(expr_format) + ) if not star_or_int_re.search(t): t = cls._alphaconv(field_index, t, expressions) @@ -1075,9 +1067,7 @@ def _expand( int(t) < cls.RANGES[field_index][0] or int(t) > cls.RANGES[field_index][1] ): - raise CroniterBadCronError( - "[{0}] is not acceptable, out of range".format(expr_format) - ) + raise CroniterBadCronError("[{0}] is not acceptable, out of range".format(expr_format)) res.append(t) @@ -1113,7 +1103,8 @@ def _expand( ): raise CroniterUnsupportedSyntaxError( "day-of-week field does not support mixing literal values and nth day of week syntax. " - "Cron: '{}' dow={} vs nth={}".format(expr_format, dow_expanded_set, nth_weekday_of_month)) + "Cron: '{}' dow={} vs nth={}".format(expr_format, dow_expanded_set, nth_weekday_of_month) + ) EXPRESSIONS[(expr_format, hash_id, second_at_beginning)] = expressions return expanded, nth_weekday_of_month @@ -1279,8 +1270,8 @@ def croniter_range( isinstance(start, type(stop)) or isinstance(stop, type(start)) ): raise CroniterBadTypeRangeError( - "The start and stop must be same type. {0} != {1}". - format(type(start), type(stop))) + "The start and stop must be same type. {0} != {1}".format(type(start), type(stop)) + ) if isinstance(start, (float, int)): start, stop = ( datetime.datetime.fromtimestamp(t, tzutc()).replace(tzinfo=None)