Skip to content

Commit 01745e1

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

File tree

1 file changed

+47
-40
lines changed

1 file changed

+47
-40
lines changed

src/croniter/croniter.py

+47-40
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
@@ -401,36 +403,32 @@ def _get_next(
401403
dom_dow_exception_processed = True
402404

403405
if not dom_dow_exception_processed:
404-
result = self._calc(self.cur, expanded,
405-
nth_weekday_of_month, is_prev)
406+
result = self._calc(self.cur, expanded, nth_weekday_of_month, is_prev)
406407

407408
# DST Handling for cron job spanning across days
408409
dtstarttime = self._timestamp_to_datetime(self.dst_start_time)
409-
dtstarttime_utcoffset = (
410-
dtstarttime.utcoffset() or datetime.timedelta(0))
410+
dtstarttime_utcoffset = dtstarttime.utcoffset() or datetime.timedelta(0)
411411
dtresult = self._timestamp_to_datetime(result)
412412
lag = lag_hours = 0
413413
# do we trigger DST on next crontab (handle backward changes)
414414
dtresult_utcoffset = dtstarttime_utcoffset
415415
if dtresult and self.tzinfo:
416416
dtresult_utcoffset = dtresult.utcoffset()
417-
lag_hours = (
418-
self._timedelta_to_seconds(dtresult - dtstarttime) / (60 * 60)
419-
)
420-
lag = self._timedelta_to_seconds(
421-
dtresult_utcoffset - dtstarttime_utcoffset
422-
)
417+
lag_hours = self._timedelta_to_seconds(dtresult - dtstarttime) / (60 * 60)
418+
lag = self._timedelta_to_seconds(dtresult_utcoffset - dtstarttime_utcoffset)
423419
hours_before_midnight = 24 - dtstarttime.hour
424420
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))
421+
if (lag > 0 and abs(lag_hours) >= hours_before_midnight) or (
422+
lag < 0
423+
and ((3600 * abs(lag_hours) + abs(lag)) >= hours_before_midnight * 3600)
429424
):
430425
dtresult_adjusted = dtresult - datetime.timedelta(seconds=lag)
431426
result_adjusted = self._datetime_to_timestamp(dtresult_adjusted)
432427
# Do the actual adjust only if the result time actually exists
433-
if self._timestamp_to_datetime(result_adjusted).tzinfo == dtresult_adjusted.tzinfo:
428+
if (
429+
self._timestamp_to_datetime(result_adjusted).tzinfo
430+
== dtresult_adjusted.tzinfo
431+
):
434432
dtresult = dtresult_adjusted
435433
result = result_adjusted
436434
self.dst_start_time = result
@@ -630,9 +628,8 @@ def proc_day_of_week_nth(d):
630628
continue
631629
else:
632630
candidate = c[n - 1]
633-
if (
634-
(is_prev and candidate <= d.day) or
635-
(not is_prev and d.day <= candidate)
631+
if (is_prev and candidate <= d.day) or (
632+
not is_prev and d.day <= candidate
636633
):
637634
candidates.append(candidate)
638635

@@ -830,9 +827,18 @@ def value_alias(cls, val, field_index, len_expressions=UNIX_CRON_LEN):
830827
# do not support 0 as a month either for classical 5 fields cron,
831828
# 6fields second repeat form or 7 fields year form
832829
# 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)
830+
(
831+
field_index in [DAY_FIELD, MONTH_FIELD]
832+
and len_expressions == UNIX_CRON_LEN
833+
)
834+
or (
835+
field_index in [MONTH_FIELD, DOW_FIELD]
836+
and len_expressions == SECOND_CRON_LEN
837+
)
838+
or (
839+
field_index in [DAY_FIELD, MONTH_FIELD, DOW_FIELD]
840+
and len_expressions == YEAR_CRON_LEN
841+
)
836842
):
837843
val = cls.LOWMAP[field_index][val]
838844
return val
@@ -985,8 +991,8 @@ def _expand(
985991

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

988-
if (
989-
max(low, high) > max(cls.RANGES[field_index][0], cls.RANGES[field_index][1])
994+
if max(low, high) > max(
995+
cls.RANGES[field_index][0], cls.RANGES[field_index][1]
990996
):
991997
raise CroniterBadCronError(
992998
"{0} is out of bands".format(expr_format)
@@ -1015,7 +1021,9 @@ def _expand(
10151021
if rng:
10161022
already_skipped = list(reversed(whole_field_range)).index(rng[-1])
10171023
curpos = whole_field_range.index(rng[-1])
1018-
if ((curpos + step) > len(whole_field_range)) and (already_skipped < step):
1024+
if ((curpos + step) > len(whole_field_range)) and (
1025+
already_skipped < step
1026+
):
10191027
to_skip = step - already_skipped
10201028
rng += list(
10211029
range(cls.RANGES[field_index][0] + to_skip, high + 1, step)
@@ -1055,10 +1063,9 @@ def _expand(
10551063

10561064
t = cls.value_alias(t, field_index, expressions)
10571065

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])
1066+
if t not in ["*", "l"] and (
1067+
int(t) < cls.RANGES[field_index][0]
1068+
or int(t) > cls.RANGES[field_index][1]
10621069
):
10631070
raise CroniterBadCronError(
10641071
"[{0}] is not acceptable, out of range".format(expr_format)
@@ -1077,9 +1084,8 @@ def _expand(
10771084
)
10781085
if len(res) == cls.LEN_MEANS_ALL[field_index]:
10791086
# 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])
1087+
if (field_index == DAY_FIELD and "*" not in expressions[DOW_FIELD]) or (
1088+
field_index == DOW_FIELD and "*" not in expressions[DAY_FIELD]
10831089
):
10841090
pass
10851091
else:
@@ -1093,7 +1099,10 @@ def _expand(
10931099
dow_expanded_set = dow_expanded_set.difference(nth_weekday_of_month.keys())
10941100
dow_expanded_set.discard("*")
10951101
# 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]:
1102+
if (
1103+
dow_expanded_set
1104+
and len(set(expanded[DOW_FIELD])) != cls.LEN_MEANS_ALL[DOW_FIELD]
1105+
):
10971106
raise CroniterUnsupportedSyntaxError(
10981107
"day-of-week field does not support mixing literal values and nth day of week syntax. "
10991108
"Cron: '{}' dow={} vs nth={}".format(expr_format, dow_expanded_set, nth_weekday_of_month))
@@ -1258,10 +1267,8 @@ def croniter_range(
12581267
_croniter = _croniter or croniter
12591268
auto_rt = datetime.datetime
12601269
# 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)))
1270+
if type(start) is not type(stop) and not (
1271+
isinstance(start, type(stop)) or isinstance(stop, type(start))
12651272
):
12661273
raise CroniterBadTypeRangeError(
12671274
"The start and stop must be same type. {0} != {1}".

0 commit comments

Comments
 (0)