11import datetime
22from _typeshed import Unused
3- from collections import OrderedDict
4- from collections .abc import Generator
3+ from collections .abc import Generator , Iterable
54from re import Match , Pattern
65from typing import Any , Final , Generic , Literal , Protocol , TypeVar , overload , type_check_only
76from typing_extensions import Never , Self , TypeAlias
87
98_R_co = TypeVar ("_R_co" , float , datetime .datetime , default = float , covariant = True )
109_R2_co = TypeVar ("_R2_co" , float , datetime .datetime , covariant = True )
1110_Expressions : TypeAlias = list [str ] # fixed-length list of 5 or 6 strings
11+ ExpandedExpression : TypeAlias = list [int | Literal ["*" , "l" ]]
1212
1313@type_check_only
1414class _AllIter (Protocol [_R_co ]):
@@ -45,10 +45,12 @@ YEAR_FIELDS: Final[tuple[int, int, int, int, int, int, int]]
4545step_search_re : Final [Pattern [str ]]
4646only_int_re : Final [Pattern [str ]]
4747
48+ DAYS : Final [tuple [int , int , int , int , int , int , int , int , int , int , int , int ]]
4849WEEKDAYS : Final [str ]
4950MONTHS : Final [str ]
5051star_or_int_re : Final [Pattern [str ]]
5152special_dow_re : Final [Pattern [str ]]
53+ nearest_weekday_re : Final [Pattern [str ]]
5254re_star : Final [Pattern [str ]]
5355hash_expression_re : Final [Pattern [str ]]
5456
@@ -57,11 +59,8 @@ UNIX_CRON_LEN: Final = 5
5759SECOND_CRON_LEN : Final = 6
5860YEAR_CRON_LEN : Final = 7
5961VALID_LEN_EXPRESSION : Final [set [int ]]
60- TIMESTAMP_TO_DT_CACHE : Final [dict [tuple [float , str ], datetime .datetime ]]
61- EXPRESSIONS : dict [tuple [str , bytes ], _Expressions ]
6262MARKER : object
6363
64- def timedelta_to_seconds (td : datetime .timedelta ) -> float : ...
6564def datetime_to_timestamp (d : datetime .datetime ) -> float : ...
6665
6766class CroniterError (ValueError ): ...
@@ -78,22 +77,6 @@ class croniter(Generic[_R_co]):
7877 tuple [int , int ], tuple [int , int ], tuple [int , int ], tuple [int , int ], tuple [int , int ], tuple [int , int ], tuple [int , int ]
7978 ]
8079 ]
81- DAYS : Final [
82- tuple [
83- Literal [31 ],
84- Literal [28 ],
85- Literal [31 ],
86- Literal [30 ],
87- Literal [31 ],
88- Literal [30 ],
89- Literal [31 ],
90- Literal [31 ],
91- Literal [30 ],
92- Literal [31 ],
93- Literal [30 ],
94- Literal [31 ],
95- ]
96- ]
9780 ALPHACONV : Final [
9881 tuple [
9982 dict [Never , Never ],
@@ -121,15 +104,15 @@ class croniter(Generic[_R_co]):
121104 second_at_beginning : bool
122105 tzinfo : datetime .tzinfo | None
123106
124- # Initialized to None, but immediately set to a float.
125107 start_time : float
126108 dst_start_time : float
127109 cur : float
128110
129111 expanded : list [list [str ]]
130112 nth_weekday_of_month : dict [str , set [int ]]
131- fields : tuple [int , ...]
132113 expressions : _Expressions
114+ nearest_weekday : set [int ]
115+ fields : tuple [int , ...]
133116
134117 @overload
135118 def __new__ (
@@ -142,7 +125,7 @@ class croniter(Generic[_R_co]):
142125 is_prev : bool = False ,
143126 hash_id : str | bytes | None = None ,
144127 implement_cron_bug : bool = False ,
145- second_at_beginning : bool | None = None ,
128+ second_at_beginning : bool = False ,
146129 expand_from_start_time : bool = False ,
147130 ) -> croniter [float ]: ...
148131 @overload
@@ -156,7 +139,7 @@ class croniter(Generic[_R_co]):
156139 is_prev : bool = False ,
157140 hash_id : str | bytes | None = None ,
158141 implement_cron_bug : bool = False ,
159- second_at_beginning : bool | None = None ,
142+ second_at_beginning : bool = False ,
160143 expand_from_start_time : bool = False ,
161144 ) -> croniter [datetime .datetime ]: ...
162145 @overload
@@ -170,7 +153,7 @@ class croniter(Generic[_R_co]):
170153 is_prev : bool = False ,
171154 hash_id : str | bytes | None = None ,
172155 implement_cron_bug : bool = False ,
173- second_at_beginning : bool | None = None ,
156+ second_at_beginning : bool = False ,
174157 expand_from_start_time : bool = False ,
175158 ) -> croniter [datetime .datetime ]: ...
176159 def __init__ (
@@ -183,7 +166,7 @@ class croniter(Generic[_R_co]):
183166 is_prev : bool = False ,
184167 hash_id : str | bytes | None = None ,
185168 implement_cron_bug : bool = False ,
186- second_at_beginning : bool | None = None ,
169+ second_at_beginning : bool = False ,
187170 expand_from_start_time : bool = False ,
188171 ) -> None : ...
189172 @overload
@@ -210,8 +193,6 @@ class croniter(Generic[_R_co]):
210193 @staticmethod
211194 def datetime_to_timestamp (d : datetime .datetime ) -> float : ...
212195 def timestamp_to_datetime (self , timestamp : float , tzinfo : datetime .tzinfo | None = ...) -> datetime .datetime : ...
213- @staticmethod
214- def timedelta_to_seconds (td : datetime .timedelta ) -> float : ...
215196 @overload
216197 def all_next (
217198 self , ret_type : type [_R2_co ], start_time : float | datetime .datetime | None = None , update_current : bool | None = None
@@ -247,26 +228,33 @@ class croniter(Generic[_R_co]):
247228 update_current : bool | None = None ,
248229 ) -> _R_co : ...
249230 __next__ = next
250- @staticmethod
251- def is_leap (year : int ) -> bool : ...
252231 @classmethod
253232 def value_alias (
254233 cls ,
255234 val : int ,
256235 field_index : Literal [0 , 1 , 2 , 3 , 4 , 5 , 6 ],
257236 len_expressions : int | list [Any ] | dict [Any , Any ] | tuple [Any , ...] | set [Any ] = 5 ,
258237 ) -> int : ...
238+ DAYS_IN_MONTH : Final [dict [int , int ]]
259239 @classmethod
260240 def expand (
261241 cls ,
262242 expr_format : str ,
263243 hash_id : bytes | None = None ,
264244 second_at_beginning : bool = False ,
265245 from_timestamp : float | None = None ,
266- ) -> tuple [list [list [str ]], dict [str , set [int ]]]: ...
246+ strict : bool = False ,
247+ strict_year : int | Iterable [int ] | None = None ,
248+ ) -> tuple [list [ExpandedExpression ], dict [str , set [int ]]]: ...
267249 @classmethod
268250 def is_valid (
269- cls , expression : str , hash_id : bytes | None = None , encoding : str = "UTF-8" , second_at_beginning : bool = False
251+ cls ,
252+ expression : str ,
253+ hash_id : bytes | None = None ,
254+ encoding : str = "UTF-8" ,
255+ second_at_beginning : bool = False ,
256+ strict : bool = False ,
257+ strict_year : int | Iterable [int ] | None = None ,
270258 ) -> bool : ...
271259 @classmethod
272260 def match (
@@ -275,6 +263,7 @@ class croniter(Generic[_R_co]):
275263 testdate : float | datetime .datetime | None ,
276264 day_or : bool = True ,
277265 second_at_beginning : bool = False ,
266+ precision_in_seconds : int | None = None ,
278267 ) -> bool : ...
279268 @classmethod
280269 def match_range (
@@ -284,6 +273,7 @@ class croniter(Generic[_R_co]):
284273 to_datetime : datetime .datetime ,
285274 day_or : bool = True ,
286275 second_at_beginning : bool = False ,
276+ precision_in_seconds : int | None = None ,
287277 ) -> bool : ...
288278
289279@overload
@@ -354,4 +344,4 @@ class HashExpander:
354344 ** kw : object ,
355345 ) -> str : ...
356346
357- EXPANDERS : OrderedDict [str , HashExpander ]
347+ EXPANDERS : dict [str , type [ HashExpander ] ]
0 commit comments