Skip to content

Commit d5611af

Browse files
authored
[python-crontab] Remove from pyrightconfig (#14322)
1 parent 4b0daf5 commit d5611af

File tree

4 files changed

+43
-19
lines changed

4 files changed

+43
-19
lines changed

pyrightconfig.stricter.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"stubs/pycurl",
8282
"stubs/Pygments",
8383
"stubs/PyMySQL",
84-
"stubs/python-crontab",
8584
"stubs/python-datemath",
8685
"stubs/python-dateutil",
8786
"stubs/python-http-client",

stubs/python-crontab/@tests/stubtest_allowlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
crontabs.CronTabs.__new__
33
# stub does not have *args argument "args", but function doesn't actually accept positional args
44
crontab.CronTab.remove_all
5+
crontab.OrderedVariableList.__init__

stubs/python-crontab/METADATA.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
version = "3.2.*"
22
upstream_repository = "https://gitlab.com/doctormo/python-crontab"
3+
requires = ["types-croniter"]

stubs/python-crontab/crontab.pyi

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
import re
22
import subprocess
3-
from _typeshed import Incomplete
3+
from _typeshed import Incomplete, StrPath
44
from builtins import range as _range
55
from collections import OrderedDict
66
from collections.abc import Callable, Generator, Iterable, Iterator
77
from datetime import datetime
88
from logging import Logger
99
from types import TracebackType
10-
from typing import Any, SupportsIndex, overload
10+
from typing import Any, Literal, Protocol, SupportsIndex, TypeVar, overload, type_check_only
1111
from typing_extensions import Self, TypeAlias
1212

13+
from croniter.croniter import croniter
1314
from 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
1832
ITEMREX: re.Pattern[str]
@@ -22,7 +36,7 @@ WEEK_ENUM: list[str]
2236
MONTH_ENUM: list[str | None]
2337
SPECIALS: dict[str, str]
2438
SPECIAL_IGNORE: list[str]
25-
S_INFO: list[dict[str, Any]]
39+
S_INFO: list[dict[str, str | int | list[str] | list[str | None]]]
2640
WINOS: bool
2741
POSIX: bool
2842
SYSTEMV: 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

Comments
 (0)