@@ -375,13 +375,15 @@ def _get_next(
375
375
376
376
# exception to support day of month and day of week as defined in cron
377
377
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 :
379
381
# If requested, handle a bug in vixie cron/ISC cron where day_of_month and day_of_week form
380
382
# an intersection (AND) instead of a union (OR) if either field is an asterisk or starts with an asterisk
381
383
# (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 ])
385
387
):
386
388
# To produce a schedule identical to the cron bug, we'll bypass the code that
387
389
# 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(
422
424
)
423
425
hours_before_midnight = 24 - dtstarttime .hour
424
426
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 )
429
430
):
430
431
dtresult_adjusted = dtresult - datetime .timedelta (seconds = lag )
431
432
result_adjusted = self ._datetime_to_timestamp (dtresult_adjusted )
432
433
# 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
+ ):
434
438
dtresult = dtresult_adjusted
435
439
result = result_adjusted
436
440
self .dst_start_time = result
@@ -630,9 +634,8 @@ def proc_day_of_week_nth(d):
630
634
continue
631
635
else :
632
636
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
636
639
):
637
640
candidates .append (candidate )
638
641
@@ -830,9 +833,18 @@ def value_alias(cls, val, field_index, len_expressions=UNIX_CRON_LEN):
830
833
# do not support 0 as a month either for classical 5 fields cron,
831
834
# 6fields second repeat form or 7 fields year form
832
835
# 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
+ )
836
848
):
837
849
val = cls .LOWMAP [field_index ][val ]
838
850
return val
@@ -985,8 +997,8 @@ def _expand(
985
997
986
998
low , high = [cls .value_alias (int (_val ), field_index , expressions ) for _val in (low , high )]
987
999
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 ]
990
1002
):
991
1003
raise CroniterBadCronError (
992
1004
"{0} is out of bands" .format (expr_format )
@@ -1015,7 +1027,9 @@ def _expand(
1015
1027
if rng :
1016
1028
already_skipped = list (reversed (whole_field_range )).index (rng [- 1 ])
1017
1029
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
+ ):
1019
1033
to_skip = step - already_skipped
1020
1034
rng += list (
1021
1035
range (cls .RANGES [field_index ][0 ] + to_skip , high + 1 , step )
@@ -1055,10 +1069,9 @@ def _expand(
1055
1069
1056
1070
t = cls .value_alias (t , field_index , expressions )
1057
1071
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 ]
1062
1075
):
1063
1076
raise CroniterBadCronError (
1064
1077
"[{0}] is not acceptable, out of range" .format (expr_format )
@@ -1077,9 +1090,8 @@ def _expand(
1077
1090
)
1078
1091
if len (res ) == cls .LEN_MEANS_ALL [field_index ]:
1079
1092
# 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 ]
1083
1095
):
1084
1096
pass
1085
1097
else :
@@ -1093,7 +1105,10 @@ def _expand(
1093
1105
dow_expanded_set = dow_expanded_set .difference (nth_weekday_of_month .keys ())
1094
1106
dow_expanded_set .discard ("*" )
1095
1107
# 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
+ ):
1097
1112
raise CroniterUnsupportedSyntaxError (
1098
1113
"day-of-week field does not support mixing literal values and nth day of week syntax. "
1099
1114
"Cron: '{}' dow={} vs nth={}" .format (expr_format , dow_expanded_set , nth_weekday_of_month ))
@@ -1258,10 +1273,8 @@ def croniter_range(
1258
1273
_croniter = _croniter or croniter
1259
1274
auto_rt = datetime .datetime
1260
1275
# 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 ))
1265
1278
):
1266
1279
raise CroniterBadTypeRangeError (
1267
1280
"The start and stop must be same type. {0} != {1}" .
0 commit comments