Skip to content

Commit e32d982

Browse files
committed
black: Format if conditions
1 parent d7507bf commit e32d982

File tree

1 file changed

+43
-30
lines changed

1 file changed

+43
-30
lines changed

src/croniter/croniter.py

+43-30
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,15 @@ def _get_next(
375375

376376
# exception to support day of month and day of week as defined in cron
377377
dom_dow_exception_processed = False
378-
if (expanded[DAY_FIELD][0] != "*" and expanded[DOW_FIELD][0] != "*") and self._day_or:
378+
if (
379+
expanded[DAY_FIELD][0] != "*" and expanded[DOW_FIELD][0] != "*"
380+
) and self._day_or:
379381
# If requested, handle a bug in vixie cron/ISC cron where day_of_month and day_of_week form
380382
# an intersection (AND) instead of a union (OR) if either field is an asterisk or starts with an asterisk
381383
# (https://crontab.guru/cron-bug.html)
382-
if (
383-
self._implement_cron_bug and
384-
(re_star.match(self.expressions[DAY_FIELD]) or re_star.match(self.expressions[DOW_FIELD]))
384+
if self._implement_cron_bug and (
385+
re_star.match(self.expressions[DAY_FIELD])
386+
or re_star.match(self.expressions[DOW_FIELD])
385387
):
386388
# To produce a schedule identical to the cron bug, we'll bypass the code that
387389
# makes a union of DOM and DOW, and instead skip to the code that does an intersect instead
@@ -422,15 +424,17 @@ def _get_next(
422424
)
423425
hours_before_midnight = 24 - dtstarttime.hour
424426
if dtresult_utcoffset != dtstarttime_utcoffset:
425-
if (
426-
(lag > 0 and abs(lag_hours) >= hours_before_midnight)
427-
or (lag < 0 and
428-
((3600 * abs(lag_hours) + abs(lag)) >= hours_before_midnight * 3600))
427+
if (lag > 0 and abs(lag_hours) >= hours_before_midnight) or (
428+
lag < 0
429+
and ((3600 * abs(lag_hours) + abs(lag)) >= hours_before_midnight * 3600)
429430
):
430431
dtresult_adjusted = dtresult - datetime.timedelta(seconds=lag)
431432
result_adjusted = self._datetime_to_timestamp(dtresult_adjusted)
432433
# Do the actual adjust only if the result time actually exists
433-
if self._timestamp_to_datetime(result_adjusted).tzinfo == dtresult_adjusted.tzinfo:
434+
if (
435+
self._timestamp_to_datetime(result_adjusted).tzinfo
436+
== dtresult_adjusted.tzinfo
437+
):
434438
dtresult = dtresult_adjusted
435439
result = result_adjusted
436440
self.dst_start_time = result
@@ -630,9 +634,8 @@ def proc_day_of_week_nth(d):
630634
continue
631635
else:
632636
candidate = c[n - 1]
633-
if (
634-
(is_prev and candidate <= d.day) or
635-
(not is_prev and d.day <= candidate)
637+
if (is_prev and candidate <= d.day) or (
638+
not is_prev and d.day <= candidate
636639
):
637640
candidates.append(candidate)
638641

@@ -830,9 +833,18 @@ def value_alias(cls, val, field_index, len_expressions=UNIX_CRON_LEN):
830833
# do not support 0 as a month either for classical 5 fields cron,
831834
# 6fields second repeat form or 7 fields year form
832835
# but still let conversion happen if day field is shifted
833-
(field_index in [DAY_FIELD, MONTH_FIELD] and len_expressions == UNIX_CRON_LEN) or
834-
(field_index in [MONTH_FIELD, DOW_FIELD] and len_expressions == SECOND_CRON_LEN) or
835-
(field_index in [DAY_FIELD, MONTH_FIELD, DOW_FIELD] and len_expressions == YEAR_CRON_LEN)
836+
(
837+
field_index in [DAY_FIELD, MONTH_FIELD]
838+
and len_expressions == UNIX_CRON_LEN
839+
)
840+
or (
841+
field_index in [MONTH_FIELD, DOW_FIELD]
842+
and len_expressions == SECOND_CRON_LEN
843+
)
844+
or (
845+
field_index in [DAY_FIELD, MONTH_FIELD, DOW_FIELD]
846+
and len_expressions == YEAR_CRON_LEN
847+
)
836848
):
837849
val = cls.LOWMAP[field_index][val]
838850
return val
@@ -985,8 +997,8 @@ def _expand(
985997

986998
low, high = [cls.value_alias(int(_val), field_index, expressions) for _val in (low, high)]
987999

988-
if (
989-
max(low, high) > max(cls.RANGES[field_index][0], cls.RANGES[field_index][1])
1000+
if max(low, high) > max(
1001+
cls.RANGES[field_index][0], cls.RANGES[field_index][1]
9901002
):
9911003
raise CroniterBadCronError(
9921004
"{0} is out of bands".format(expr_format)
@@ -1015,7 +1027,9 @@ def _expand(
10151027
if rng:
10161028
already_skipped = list(reversed(whole_field_range)).index(rng[-1])
10171029
curpos = whole_field_range.index(rng[-1])
1018-
if ((curpos + step) > len(whole_field_range)) and (already_skipped < step):
1030+
if ((curpos + step) > len(whole_field_range)) and (
1031+
already_skipped < step
1032+
):
10191033
to_skip = step - already_skipped
10201034
rng += list(
10211035
range(cls.RANGES[field_index][0] + to_skip, high + 1, step)
@@ -1055,10 +1069,9 @@ def _expand(
10551069

10561070
t = cls.value_alias(t, field_index, expressions)
10571071

1058-
if (
1059-
t not in ["*", "l"]
1060-
and (int(t) < cls.RANGES[field_index][0] or
1061-
int(t) > cls.RANGES[field_index][1])
1072+
if t not in ["*", "l"] and (
1073+
int(t) < cls.RANGES[field_index][0]
1074+
or int(t) > cls.RANGES[field_index][1]
10621075
):
10631076
raise CroniterBadCronError(
10641077
"[{0}] is not acceptable, out of range".format(expr_format)
@@ -1077,9 +1090,8 @@ def _expand(
10771090
)
10781091
if len(res) == cls.LEN_MEANS_ALL[field_index]:
10791092
# Make sure the wildcard is used in the correct way (avoid over-optimization)
1080-
if (
1081-
(field_index == DAY_FIELD and "*" not in expressions[DOW_FIELD]) or
1082-
(field_index == DOW_FIELD and "*" not in expressions[DAY_FIELD])
1093+
if (field_index == DAY_FIELD and "*" not in expressions[DOW_FIELD]) or (
1094+
field_index == DOW_FIELD and "*" not in expressions[DAY_FIELD]
10831095
):
10841096
pass
10851097
else:
@@ -1093,7 +1105,10 @@ def _expand(
10931105
dow_expanded_set = dow_expanded_set.difference(nth_weekday_of_month.keys())
10941106
dow_expanded_set.discard("*")
10951107
# Skip: if it's all weeks instead of wildcard
1096-
if dow_expanded_set and len(set(expanded[DOW_FIELD])) != cls.LEN_MEANS_ALL[DOW_FIELD]:
1108+
if (
1109+
dow_expanded_set
1110+
and len(set(expanded[DOW_FIELD])) != cls.LEN_MEANS_ALL[DOW_FIELD]
1111+
):
10971112
raise CroniterUnsupportedSyntaxError(
10981113
"day-of-week field does not support mixing literal values and nth day of week syntax. "
10991114
"Cron: '{}' dow={} vs nth={}".format(expr_format, dow_expanded_set, nth_weekday_of_month))
@@ -1258,10 +1273,8 @@ def croniter_range(
12581273
_croniter = _croniter or croniter
12591274
auto_rt = datetime.datetime
12601275
# type is used in first if branch for perfs reasons
1261-
if (
1262-
type(start) is not type(stop) and not (
1263-
isinstance(start, type(stop)) or
1264-
isinstance(stop, type(start)))
1276+
if type(start) is not type(stop) and not (
1277+
isinstance(start, type(stop)) or isinstance(stop, type(start))
12651278
):
12661279
raise CroniterBadTypeRangeError(
12671280
"The start and stop must be same type. {0} != {1}".

0 commit comments

Comments
 (0)