Skip to content

Commit

Permalink
Merge branch 'master' into cron-trigger-dst-fold-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm authored Jan 12, 2025
2 parents 7455b52 + 8548e7f commit 3fadd59
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 36 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# * Run "pre-commit install".
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -20,14 +20,14 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.7
rev: v0.8.6
hooks:
- id: ruff
args: [--fix, --show-fixes]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
rev: v1.14.1
hooks:
- id: mypy
additional_dependencies:
Expand Down
31 changes: 12 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test = [
"anyio[trio]",
"asyncmy >= 0.2.5; python_implementation == 'CPython'",
"coverage >= 7",
"psycopg",
"psycopg[binary]",
"pymongo >= 4",
"pymysql[rsa]",
"PySide6 >= 6.6; python_implementation == 'CPython' and python_version < '3.13'",
Expand Down Expand Up @@ -119,25 +119,18 @@ ignore_missing_imports = true
disable_error_code = "type-abstract"

[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py38, py39, py310, py311, py312, py313, pypy3
env_list = ["py39", "py310", "py311", "py312", "py313", "py314", "pypy3"]
skip_missing_interpreters = true
minversion = 4.0

[testenv]
extras = test
package = editable
commands = coverage run -m pytest {posargs}
[tool.tox.env_run_base]
commands = [["pytest", { replace = "posargs", extend = true }]]
package = "editable"
extras = ["test"]

[testenv:pypy3]
commands = pytest {posargs}
[tool.tox.env.pyright]
commands = [["pyright", "--verifytypes", "apscheduler"]]
deps = ["pyright"]

[testenv:pyright]
deps = pyright
commands = pyright --verifytypes apscheduler
[testenv:docs]
extras = doc
commands = sphinx-build -W -n docs build/sphinx
"""
[tool.tox.env.docs]
commands = [["sphinx-build", "-W", "-n", "docs", "build/sphinx"]]
extras = ["doc"]
21 changes: 9 additions & 12 deletions src/apscheduler/_converters.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from __future__ import annotations

from collections.abc import Callable
from datetime import date, datetime, timedelta, timezone
from datetime import date, datetime, timedelta, timezone, tzinfo
from typing import Any
from uuid import UUID
from zoneinfo import ZoneInfo

from tzlocal import get_localzone


def as_int(value: Any) -> Any:
def as_int(value: int | str) -> int:
if isinstance(value, str):
return int(value)

return value


def as_aware_datetime(value: Any) -> Any:
def as_aware_datetime(value: datetime | str) -> datetime:
if isinstance(value, str):
# Before Python 3.11, fromisoformat() could not handle the "Z" suffix
if value.upper().endswith("Z"):
Expand All @@ -30,33 +30,30 @@ def as_aware_datetime(value: Any) -> Any:
return value


def as_date(value: Any) -> Any:
def as_date(value: date | str) -> date:
if isinstance(value, str):
return date.fromisoformat(value)

return value


def as_timezone(value: Any) -> Any:
def as_timezone(value: tzinfo | str) -> tzinfo:
if isinstance(value, str):
if value is None or value == "local":
return get_localzone()

return ZoneInfo(value)
return get_localzone() if value == "local" else ZoneInfo(value)
elif value is timezone.utc:
return ZoneInfo("UTC")

return value


def as_uuid(value: Any) -> Any:
def as_uuid(value: UUID | str) -> UUID:
if isinstance(value, str):
return UUID(value)

return value


def as_timedelta(value: Any) -> Any:
def as_timedelta(value: timedelta | int) -> timedelta:
if isinstance(value, (float, int)):
return timedelta(seconds=value)

Expand All @@ -66,7 +63,7 @@ def as_timedelta(value: Any) -> Any:
def as_enum(enum_class: Any) -> Callable[[Any], Any]:
def converter(value: Any) -> Any:
if isinstance(value, str):
return enum_class.__members__[value]
return enum_class[value]

return value

Expand Down
2 changes: 1 addition & 1 deletion src/apscheduler/triggers/cron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def from_crontab(
*,
start_time: datetime | None = None,
end_time: datetime | None = None,
timezone: str | tzinfo = "local",
timezone: tzinfo | str = "local",
) -> CronTrigger:
"""
Create a :class:`~CronTrigger` from a standard crontab expression.
Expand Down
2 changes: 1 addition & 1 deletion src/apscheduler/triggers/cron/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@


class BaseField:
__slots__ = "name", "expressions"
__slots__ = "expressions", "name"

real: ClassVar[bool] = True
compilers: ClassVar[Any] = (AllExpression, RangeExpression)
Expand Down

0 comments on commit 3fadd59

Please sign in to comment.