Skip to content

Commit e73dff2

Browse files
authored
Merge pull request #124 from evanpurkhiser/black-if-conditions
black: Format if conditions
2 parents 044f014 + 8bd1106 commit e73dff2

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

src/croniter/croniter.py

+31-27
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,15 @@ def _get_next(
386386

387387
# exception to support day of month and day of week as defined in cron
388388
dom_dow_exception_processed = False
389-
if (expanded[DAY_FIELD][0] != "*" and expanded[DOW_FIELD][0] != "*") and self._day_or:
389+
if (
390+
expanded[DAY_FIELD][0] != "*" and expanded[DOW_FIELD][0] != "*"
391+
) and self._day_or:
390392
# If requested, handle a bug in vixie cron/ISC cron where day_of_month and day_of_week form
391393
# an intersection (AND) instead of a union (OR) if either field is an asterisk or starts with an asterisk
392394
# (https://crontab.guru/cron-bug.html)
393-
if (
394-
self._implement_cron_bug and
395-
(re_star.match(self.expressions[DAY_FIELD]) or re_star.match(self.expressions[DOW_FIELD]))
395+
if self._implement_cron_bug and (
396+
re_star.match(self.expressions[DAY_FIELD])
397+
or re_star.match(self.expressions[DOW_FIELD])
396398
):
397399
# To produce a schedule identical to the cron bug, we'll bypass the code that
398400
# makes a union of DOM and DOW, and instead skip to the code that does an intersect instead
@@ -433,15 +435,17 @@ def _get_next(
433435
)
434436
hours_before_midnight = 24 - dtstarttime.hour
435437
if dtresult_utcoffset != dtstarttime_utcoffset:
436-
if (
437-
(lag > 0 and abs(lag_hours) >= hours_before_midnight)
438-
or (lag < 0 and
439-
((3600 * abs(lag_hours) + abs(lag)) >= hours_before_midnight * 3600))
438+
if (lag > 0 and abs(lag_hours) >= hours_before_midnight) or (
439+
lag < 0
440+
and ((3600 * abs(lag_hours) + abs(lag)) >= hours_before_midnight * 3600)
440441
):
441442
dtresult_adjusted = dtresult - datetime.timedelta(seconds=lag)
442443
result_adjusted = self._datetime_to_timestamp(dtresult_adjusted)
443444
# Do the actual adjust only if the result time actually exists
444-
if self._timestamp_to_datetime(result_adjusted).tzinfo == dtresult_adjusted.tzinfo:
445+
if (
446+
self._timestamp_to_datetime(result_adjusted).tzinfo
447+
== dtresult_adjusted.tzinfo
448+
):
445449
dtresult = dtresult_adjusted
446450
result = result_adjusted
447451
self.dst_start_time = result
@@ -642,9 +646,8 @@ def proc_day_of_week_nth(d):
642646
continue
643647
else:
644648
candidate = c[n - 1]
645-
if (
646-
(is_prev and candidate <= d.day) or
647-
(not is_prev and d.day <= candidate)
649+
if (is_prev and candidate <= d.day) or (
650+
not is_prev and d.day <= candidate
648651
):
649652
candidates.append(candidate)
650653

@@ -997,8 +1000,8 @@ def _expand(
9971000

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

1000-
if (
1001-
max(low, high) > max(cls.RANGES[field_index][0], cls.RANGES[field_index][1])
1003+
if max(low, high) > max(
1004+
cls.RANGES[field_index][0], cls.RANGES[field_index][1]
10021005
):
10031006
raise CroniterBadCronError(
10041007
"{0} is out of bands".format(expr_format)
@@ -1027,7 +1030,9 @@ def _expand(
10271030
if rng:
10281031
already_skipped = list(reversed(whole_field_range)).index(rng[-1])
10291032
curpos = whole_field_range.index(rng[-1])
1030-
if ((curpos + step) > len(whole_field_range)) and (already_skipped < step):
1033+
if ((curpos + step) > len(whole_field_range)) and (
1034+
already_skipped < step
1035+
):
10311036
to_skip = step - already_skipped
10321037
rng += list(
10331038
range(cls.RANGES[field_index][0] + to_skip, high + 1, step)
@@ -1067,10 +1072,9 @@ def _expand(
10671072

10681073
t = cls.value_alias(t, field_index, expressions)
10691074

1070-
if (
1071-
t not in ["*", "l"]
1072-
and (int(t) < cls.RANGES[field_index][0] or
1073-
int(t) > cls.RANGES[field_index][1])
1075+
if t not in ["*", "l"] and (
1076+
int(t) < cls.RANGES[field_index][0]
1077+
or int(t) > cls.RANGES[field_index][1]
10741078
):
10751079
raise CroniterBadCronError(
10761080
"[{0}] is not acceptable, out of range".format(expr_format)
@@ -1089,9 +1093,8 @@ def _expand(
10891093
)
10901094
if len(res) == cls.LEN_MEANS_ALL[field_index]:
10911095
# Make sure the wildcard is used in the correct way (avoid over-optimization)
1092-
if (
1093-
(field_index == DAY_FIELD and "*" not in expressions[DOW_FIELD]) or
1094-
(field_index == DOW_FIELD and "*" not in expressions[DAY_FIELD])
1096+
if (field_index == DAY_FIELD and "*" not in expressions[DOW_FIELD]) or (
1097+
field_index == DOW_FIELD and "*" not in expressions[DAY_FIELD]
10951098
):
10961099
pass
10971100
else:
@@ -1105,7 +1108,10 @@ def _expand(
11051108
dow_expanded_set = dow_expanded_set.difference(nth_weekday_of_month.keys())
11061109
dow_expanded_set.discard("*")
11071110
# Skip: if it's all weeks instead of wildcard
1108-
if dow_expanded_set and len(set(expanded[DOW_FIELD])) != cls.LEN_MEANS_ALL[DOW_FIELD]:
1111+
if (
1112+
dow_expanded_set
1113+
and len(set(expanded[DOW_FIELD])) != cls.LEN_MEANS_ALL[DOW_FIELD]
1114+
):
11091115
raise CroniterUnsupportedSyntaxError(
11101116
"day-of-week field does not support mixing literal values and nth day of week syntax. "
11111117
"Cron: '{}' dow={} vs nth={}".format(expr_format, dow_expanded_set, nth_weekday_of_month))
@@ -1270,10 +1276,8 @@ def croniter_range(
12701276
_croniter = _croniter or croniter
12711277
auto_rt = datetime.datetime
12721278
# type is used in first if branch for perfs reasons
1273-
if (
1274-
type(start) is not type(stop) and not (
1275-
isinstance(start, type(stop)) or
1276-
isinstance(stop, type(start)))
1279+
if type(start) is not type(stop) and not (
1280+
isinstance(start, type(stop)) or isinstance(stop, type(start))
12771281
):
12781282
raise CroniterBadTypeRangeError(
12791283
"The start and stop must be same type. {0} != {1}".

0 commit comments

Comments
 (0)