11import re
22import subprocess
3- from _typeshed import Incomplete
3+ from _typeshed import Incomplete , StrPath
44from builtins import range as _range
55from collections import OrderedDict
66from collections .abc import Callable , Generator , Iterable , Iterator
77from datetime import datetime
88from logging import Logger
99from types import TracebackType
10- from typing import Any , SupportsIndex , overload
10+ from typing import Any , Literal , Protocol , SupportsIndex , TypeVar , overload , type_check_only
1111from typing_extensions import Self , TypeAlias
1212
13+ from croniter .croniter import croniter
1314from cronlog import CronLog
1415
1516_User : TypeAlias = str | bool | None
17+ _K = TypeVar ("_K" )
18+ _V = TypeVar ("_V" )
19+
20+ # cron_descriptor.Options class
21+ @type_check_only
22+ class _Options (Protocol ):
23+ casing_type : Literal [1 , 2 , 3 ]
24+ verbose : bool
25+ day_of_week_start_index_zero : bool
26+ use_24hour_time_format : bool
27+ locale_location : StrPath | None
28+ locale_code : str | None
29+ def __init__ (self ) -> None : ...
1630
1731__pkgname__ : str
1832ITEMREX : re .Pattern [str ]
@@ -22,7 +36,7 @@ WEEK_ENUM: list[str]
2236MONTH_ENUM : list [str | None ]
2337SPECIALS : dict [str , str ]
2438SPECIAL_IGNORE : list [str ]
25- S_INFO : list [dict [str , Any ]]
39+ S_INFO : list [dict [str , str | int | list [ str ] | list [ str | None ] ]]
2640WINOS : bool
2741POSIX : bool
2842SYSTEMV : bool
@@ -50,7 +64,7 @@ class CronTab:
5064 crons : list [CronItem ] | None
5165 filen : str | None
5266 cron_command : str
53- env : OrderedVariableList | None
67+ env : OrderedVariableList [ Incomplete , Incomplete ] | None
5468 root : bool
5569 intab : str | None
5670 tabfile : str | None
@@ -73,13 +87,13 @@ class CronTab:
7387 item : CronItem ,
7488 line : str = ...,
7589 read : bool = ...,
76- before : str | re .Pattern [str ] | list [CronItem ] | tuple [CronItem , ...] | Generator [CronItem , Any , Any ] | None = ...,
90+ before : str | re .Pattern [str ] | list [CronItem ] | tuple [CronItem , ...] | Generator [CronItem ] | None = ...,
7791 ) -> None : ...
7892 def write (self , filename : str | None = ..., user : _User = ..., errors : bool = ...) -> None : ...
7993 def write_to_user (self , user : bool | str = ...) -> None : ...
8094 # Usually `kwargs` are just `now: datetime | None`, but technically this can
8195 # work for `CronItem` subclasses, which might define other kwargs.
82- def run_pending (self , ** kwargs : Any ) -> Iterator [str ]: ...
96+ def run_pending (self , * , now : datetime | None = ..., * *kwargs : Any ) -> Iterator [str ]: ...
8397 def run_scheduler (self , timeout : int = - 1 , cadence : int = 60 , warp : bool = False ) -> Iterator [str ]: ...
8498 def render (self , errors : bool = ..., specials : bool | None = ...) -> str : ...
8599 def new (
@@ -88,7 +102,7 @@ class CronTab:
88102 comment : str = ...,
89103 user : str | None = ...,
90104 pre_comment : bool = ...,
91- before : str | re .Pattern [str ] | list [CronItem ] | tuple [CronItem , ...] | Generator [CronItem , Any , Any ] | None = ...,
105+ before : str | re .Pattern [str ] | list [CronItem ] | tuple [CronItem , ...] | Generator [CronItem ] | None = ...,
92106 ) -> CronItem : ...
93107 def find_command (self , command : str | re .Pattern [str ]) -> Iterator [CronItem ]: ...
94108 def find_comment (self , comment : str | re .Pattern [str ]) -> Iterator [CronItem ]: ...
@@ -116,7 +130,7 @@ class CronItem:
116130 comment : str
117131 command : str | None
118132 last_run : datetime | None
119- env : OrderedVariableList
133+ env : OrderedVariableList [ Incomplete , Incomplete ]
120134 pre_comment : bool
121135 marker : str | None
122136 stdin : str | None
@@ -157,10 +171,18 @@ class CronItem:
157171 def frequency_at_hour (self , year : None = None , month : None = None , day : None = None , hour : None = None ) -> int : ...
158172 def run_pending (self , now : datetime | None = ...) -> int | str : ...
159173 def run (self ) -> str : ...
160- # TODO: use types from `croniter` module here:
161- def schedule (self , date_from : datetime | None = ...): ...
162- # TODO: use types from `cron_descriptor` here:
163- def description (self , ** kw ): ...
174+ def schedule (self , date_from : datetime | None = ...) -> croniter : ...
175+ def description (
176+ self ,
177+ * ,
178+ options : _Options | None = None ,
179+ casing_type : Literal [1 , 2 , 3 ] = 2 ,
180+ verbose : bool = False ,
181+ day_of_week_start_index_zero : bool = True ,
182+ use_24hour_time_format : bool = ...,
183+ locale_location : StrPath | None = None ,
184+ locale_code : str | None = ...,
185+ ) -> str | None : ...
164186 @property
165187 def log (self ) -> CronLog : ...
166188 @property
@@ -288,11 +310,12 @@ class CronRange:
288310 def __gt__ (self , value : object ) -> bool : ...
289311 def __int__ (self ) -> int : ...
290312
291- # TODO: make generic
292- class OrderedVariableList (OrderedDict [Incomplete , Incomplete ]):
293- job : Incomplete
294- def __init__ (self , * args : Any , ** kw : Any ) -> None : ...
313+ class OrderedVariableList (OrderedDict [_K , _V ]):
314+ job : CronItem | None
315+ # You cannot actually pass `*args`, it will raise an exception,
316+ # also known kwargs are added:
317+ def __init__ (self , * , job : CronItem | None = None , ** kw : _V ) -> None : ...
295318 @property
296- def previous (self ): ...
319+ def previous (self ) -> Self | None : ...
297320 def all (self ) -> Self : ...
298- def __getitem__ (self , key ) : ...
321+ def __getitem__ (self , key : _K ) -> _V : ...
0 commit comments