1
1
import re
2
2
import subprocess
3
- from _typeshed import Incomplete
3
+ from _typeshed import Incomplete , StrPath
4
4
from builtins import range as _range
5
5
from collections import OrderedDict
6
6
from collections .abc import Callable , Generator , Iterable , Iterator
7
7
from datetime import datetime
8
8
from logging import Logger
9
9
from types import TracebackType
10
- from typing import Any , SupportsIndex , overload
10
+ from typing import Any , Literal , Protocol , SupportsIndex , TypeVar , overload , type_check_only
11
11
from typing_extensions import Self , TypeAlias
12
12
13
+ from croniter .croniter import croniter
13
14
from cronlog import CronLog
14
15
15
16
_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 : ...
16
30
17
31
__pkgname__ : str
18
32
ITEMREX : re .Pattern [str ]
@@ -22,7 +36,7 @@ WEEK_ENUM: list[str]
22
36
MONTH_ENUM : list [str | None ]
23
37
SPECIALS : dict [str , str ]
24
38
SPECIAL_IGNORE : list [str ]
25
- S_INFO : list [dict [str , Any ]]
39
+ S_INFO : list [dict [str , str | int | list [ str ] | list [ str | None ] ]]
26
40
WINOS : bool
27
41
POSIX : bool
28
42
SYSTEMV : bool
@@ -50,7 +64,7 @@ class CronTab:
50
64
crons : list [CronItem ] | None
51
65
filen : str | None
52
66
cron_command : str
53
- env : OrderedVariableList | None
67
+ env : OrderedVariableList [ Incomplete , Incomplete ] | None
54
68
root : bool
55
69
intab : str | None
56
70
tabfile : str | None
@@ -73,13 +87,13 @@ class CronTab:
73
87
item : CronItem ,
74
88
line : str = ...,
75
89
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 = ...,
77
91
) -> None : ...
78
92
def write (self , filename : str | None = ..., user : _User = ..., errors : bool = ...) -> None : ...
79
93
def write_to_user (self , user : bool | str = ...) -> None : ...
80
94
# Usually `kwargs` are just `now: datetime | None`, but technically this can
81
95
# 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 ]: ...
83
97
def run_scheduler (self , timeout : int = - 1 , cadence : int = 60 , warp : bool = False ) -> Iterator [str ]: ...
84
98
def render (self , errors : bool = ..., specials : bool | None = ...) -> str : ...
85
99
def new (
@@ -88,7 +102,7 @@ class CronTab:
88
102
comment : str = ...,
89
103
user : str | None = ...,
90
104
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 = ...,
92
106
) -> CronItem : ...
93
107
def find_command (self , command : str | re .Pattern [str ]) -> Iterator [CronItem ]: ...
94
108
def find_comment (self , comment : str | re .Pattern [str ]) -> Iterator [CronItem ]: ...
@@ -116,7 +130,7 @@ class CronItem:
116
130
comment : str
117
131
command : str | None
118
132
last_run : datetime | None
119
- env : OrderedVariableList
133
+ env : OrderedVariableList [ Incomplete , Incomplete ]
120
134
pre_comment : bool
121
135
marker : str | None
122
136
stdin : str | None
@@ -157,10 +171,18 @@ class CronItem:
157
171
def frequency_at_hour (self , year : None = None , month : None = None , day : None = None , hour : None = None ) -> int : ...
158
172
def run_pending (self , now : datetime | None = ...) -> int | str : ...
159
173
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 : ...
164
186
@property
165
187
def log (self ) -> CronLog : ...
166
188
@property
@@ -288,11 +310,12 @@ class CronRange:
288
310
def __gt__ (self , value : object ) -> bool : ...
289
311
def __int__ (self ) -> int : ...
290
312
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 : ...
295
318
@property
296
- def previous (self ): ...
319
+ def previous (self ) -> Self | None : ...
297
320
def all (self ) -> Self : ...
298
- def __getitem__ (self , key ) : ...
321
+ def __getitem__ (self , key : _K ) -> _V : ...
0 commit comments