Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stubs/croniter/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
croniter.tests.*
2 changes: 1 addition & 1 deletion stubs/croniter/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "6.0.0"
version = "6.2.0"
upstream_repository = "https://github.com/pallets-eco/croniter"
21 changes: 21 additions & 0 deletions stubs/croniter/croniter/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,24 @@ from .croniter import (
)

cron_m = croniter_m

__all__ = [
"DAY_FIELD",
"HOUR_FIELD",
"MINUTE_FIELD",
"MONTH_FIELD",
"OVERFLOW32B_MODE",
"SECOND_FIELD",
"UTC_DT",
"YEAR_FIELD",
"CroniterBadCronError",
"CroniterBadDateError",
"CroniterBadTypeRangeError",
"CroniterError",
"CroniterNotAlphaError",
"CroniterUnsupportedSyntaxError",
"cron_m",
"croniter",
"croniter_range",
"datetime_to_timestamp",
]
58 changes: 24 additions & 34 deletions stubs/croniter/croniter/croniter.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import datetime
from _typeshed import Unused
from collections import OrderedDict
from collections.abc import Generator
from collections.abc import Generator, Iterable
from re import Match, Pattern
from typing import Any, Final, Generic, Literal, Protocol, TypeVar, overload, type_check_only
from typing_extensions import Never, Self, TypeAlias

_R_co = TypeVar("_R_co", float, datetime.datetime, default=float, covariant=True)
_R2_co = TypeVar("_R2_co", float, datetime.datetime, covariant=True)
_Expressions: TypeAlias = list[str] # fixed-length list of 5 or 6 strings
ExpandedExpression: TypeAlias = list[int | Literal["*", "l"]]

@type_check_only
class _AllIter(Protocol[_R_co]):
Expand Down Expand Up @@ -45,10 +45,12 @@ YEAR_FIELDS: Final[tuple[int, int, int, int, int, int, int]]
step_search_re: Final[Pattern[str]]
only_int_re: Final[Pattern[str]]

DAYS: Final[tuple[int, int, int, int, int, int, int, int, int, int, int, int]]
WEEKDAYS: Final[str]
MONTHS: Final[str]
star_or_int_re: Final[Pattern[str]]
special_dow_re: Final[Pattern[str]]
nearest_weekday_re: Final[Pattern[str]]
re_star: Final[Pattern[str]]
hash_expression_re: Final[Pattern[str]]

Expand All @@ -57,11 +59,8 @@ UNIX_CRON_LEN: Final = 5
SECOND_CRON_LEN: Final = 6
YEAR_CRON_LEN: Final = 7
VALID_LEN_EXPRESSION: Final[set[int]]
TIMESTAMP_TO_DT_CACHE: Final[dict[tuple[float, str], datetime.datetime]]
EXPRESSIONS: dict[tuple[str, bytes], _Expressions]
MARKER: object

def timedelta_to_seconds(td: datetime.timedelta) -> float: ...
def datetime_to_timestamp(d: datetime.datetime) -> float: ...

class CroniterError(ValueError): ...
Expand All @@ -78,22 +77,6 @@ class croniter(Generic[_R_co]):
tuple[int, int], tuple[int, int], tuple[int, int], tuple[int, int], tuple[int, int], tuple[int, int], tuple[int, int]
]
]
DAYS: Final[
tuple[
Literal[31],
Literal[28],
Literal[31],
Literal[30],
Literal[31],
Literal[30],
Literal[31],
Literal[31],
Literal[30],
Literal[31],
Literal[30],
Literal[31],
]
]
ALPHACONV: Final[
tuple[
dict[Never, Never],
Expand Down Expand Up @@ -121,15 +104,15 @@ class croniter(Generic[_R_co]):
second_at_beginning: bool
tzinfo: datetime.tzinfo | None

# Initialized to None, but immediately set to a float.
start_time: float
dst_start_time: float
cur: float

expanded: list[list[str]]
nth_weekday_of_month: dict[str, set[int]]
fields: tuple[int, ...]
expressions: _Expressions
nearest_weekday: set[int]
fields: tuple[int, ...]

@overload
def __new__(
Expand All @@ -142,7 +125,7 @@ class croniter(Generic[_R_co]):
is_prev: bool = False,
hash_id: str | bytes | None = None,
implement_cron_bug: bool = False,
second_at_beginning: bool | None = None,
second_at_beginning: bool = False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, supplying None would still work, but considering there's no primer output and using bool is what is intended, I think not allowing it here is okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to leave only bool, so it would be like in other methods/params. I think if we allow None, then we should do the same for many other parameters

expand_from_start_time: bool = False,
) -> croniter[float]: ...
@overload
Expand All @@ -156,7 +139,7 @@ class croniter(Generic[_R_co]):
is_prev: bool = False,
hash_id: str | bytes | None = None,
implement_cron_bug: bool = False,
second_at_beginning: bool | None = None,
second_at_beginning: bool = False,
expand_from_start_time: bool = False,
) -> croniter[datetime.datetime]: ...
@overload
Expand All @@ -170,7 +153,7 @@ class croniter(Generic[_R_co]):
is_prev: bool = False,
hash_id: str | bytes | None = None,
implement_cron_bug: bool = False,
second_at_beginning: bool | None = None,
second_at_beginning: bool = False,
expand_from_start_time: bool = False,
) -> croniter[datetime.datetime]: ...
def __init__(
Expand All @@ -183,7 +166,7 @@ class croniter(Generic[_R_co]):
is_prev: bool = False,
hash_id: str | bytes | None = None,
implement_cron_bug: bool = False,
second_at_beginning: bool | None = None,
second_at_beginning: bool = False,
expand_from_start_time: bool = False,
) -> None: ...
@overload
Expand All @@ -210,8 +193,6 @@ class croniter(Generic[_R_co]):
@staticmethod
def datetime_to_timestamp(d: datetime.datetime) -> float: ...
def timestamp_to_datetime(self, timestamp: float, tzinfo: datetime.tzinfo | None = ...) -> datetime.datetime: ...
@staticmethod
def timedelta_to_seconds(td: datetime.timedelta) -> float: ...
@overload
def all_next(
self, ret_type: type[_R2_co], start_time: float | datetime.datetime | None = None, update_current: bool | None = None
Expand Down Expand Up @@ -247,26 +228,33 @@ class croniter(Generic[_R_co]):
update_current: bool | None = None,
) -> _R_co: ...
__next__ = next
@staticmethod
def is_leap(year: int) -> bool: ...
@classmethod
def value_alias(
cls,
val: int,
field_index: Literal[0, 1, 2, 3, 4, 5, 6],
len_expressions: int | list[Any] | dict[Any, Any] | tuple[Any, ...] | set[Any] = 5,
) -> int: ...
DAYS_IN_MONTH: Final[dict[int, int]]
@classmethod
def expand(
cls,
expr_format: str,
hash_id: bytes | None = None,
second_at_beginning: bool = False,
from_timestamp: float | None = None,
) -> tuple[list[list[str]], dict[str, set[int]]]: ...
strict: bool = False,
strict_year: int | Iterable[int] | None = None,
) -> tuple[list[ExpandedExpression], dict[str, set[int]]]: ...
@classmethod
def is_valid(
cls, expression: str, hash_id: bytes | None = None, encoding: str = "UTF-8", second_at_beginning: bool = False
cls,
expression: str,
hash_id: bytes | None = None,
encoding: str = "UTF-8",
second_at_beginning: bool = False,
strict: bool = False,
strict_year: int | Iterable[int] | None = None,
) -> bool: ...
@classmethod
def match(
Expand All @@ -275,6 +263,7 @@ class croniter(Generic[_R_co]):
testdate: float | datetime.datetime | None,
day_or: bool = True,
second_at_beginning: bool = False,
precision_in_seconds: int | None = None,
) -> bool: ...
@classmethod
def match_range(
Expand All @@ -284,6 +273,7 @@ class croniter(Generic[_R_co]):
to_datetime: datetime.datetime,
day_or: bool = True,
second_at_beginning: bool = False,
precision_in_seconds: int | None = None,
) -> bool: ...

@overload
Expand Down Expand Up @@ -354,4 +344,4 @@ class HashExpander:
**kw: object,
) -> str: ...

EXPANDERS: OrderedDict[str, HashExpander]
EXPANDERS: dict[str, type[HashExpander]]
Loading