Skip to content

Commit

Permalink
Add type parameters for generic types
Browse files Browse the repository at this point in the history
- Callable
- Iterable
- TaskStatus
  • Loading branch information
injust committed Aug 6, 2024
1 parent 25cac59 commit 1eabad7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
18 changes: 9 additions & 9 deletions src/apscheduler/_schedulers/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ async def configure_task(
self,
func_or_task_id: TaskType,
*,
func: Callable | UnsetValue = unset,
func: Callable[..., Any] | UnsetValue = unset,
job_executor: str | UnsetValue = unset,
misfire_grace_time: float | timedelta | None | UnsetValue = unset,
max_running_jobs: int | None | UnsetValue = unset,
Expand Down Expand Up @@ -459,7 +459,7 @@ async def add_schedule(
trigger: Trigger,
*,
id: str | None = None,
args: Iterable | None = None,
args: Iterable[Any] | None = None,
kwargs: Mapping[str, Any] | None = None,
paused: bool = False,
coalesce: CoalescePolicy = CoalescePolicy.latest,
Expand Down Expand Up @@ -642,7 +642,7 @@ async def add_job(
self,
func_or_task_id: TaskType,
*,
args: Iterable | None = None,
args: Iterable[Any] | None = None,
kwargs: Mapping[str, Any] | None = None,
job_executor: str | UnsetValue = unset,
metadata: MetadataType | UnsetValue = unset,
Expand Down Expand Up @@ -745,9 +745,9 @@ def listener(event: JobReleased) -> None:

async def run_job(
self,
func_or_task_id: str | Callable,
func_or_task_id: str | Callable[..., Any],
*,
args: Iterable | None = None,
args: Iterable[Any] | None = None,
kwargs: Mapping[str, Any] | None = None,
job_executor: str | UnsetValue = unset,
metadata: MetadataType | UnsetValue = unset,
Expand Down Expand Up @@ -838,7 +838,7 @@ async def start_in_background(self) -> None:
)

async def run_until_stopped(
self, *, task_status: TaskStatus = TASK_STATUS_IGNORED
self, *, task_status: TaskStatus[None] = TASK_STATUS_IGNORED
) -> None:
"""Run the scheduler until explicitly stopped."""
if self._state is not RunState.stopped:
Expand Down Expand Up @@ -911,7 +911,7 @@ async def run_until_stopped(
SchedulerStopped(exception=exception)
)

async def _process_schedules(self, *, task_status: TaskStatus) -> None:
async def _process_schedules(self, *, task_status: TaskStatus[None]) -> None:
wakeup_event = anyio.Event()
wakeup_deadline: datetime | None = None

Expand Down Expand Up @@ -1100,7 +1100,7 @@ def _get_task_callable(self, task: Task) -> Callable:
f"callable."
)

async def _process_jobs(self, *, task_status: TaskStatus) -> None:
async def _process_jobs(self, *, task_status: TaskStatus[None]) -> None:
wakeup_event = anyio.Event()

async def check_queue_capacity(event: Event) -> None:
Expand Down Expand Up @@ -1161,7 +1161,7 @@ async def extend_job_leases() -> None:
await wakeup_event.wait()
wakeup_event = anyio.Event()

async def _run_job(self, job: Job, func: Callable, executor: str) -> None:
async def _run_job(self, job: Job, func: Callable[..., Any], executor: str) -> None:
try:
# Check if the job started before the deadline
start_time = datetime.now(timezone.utc)
Expand Down
10 changes: 5 additions & 5 deletions src/apscheduler/_schedulers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def configure_task(
self,
func_or_task_id: TaskType,
*,
func: Callable | UnsetValue = unset,
func: Callable[..., Any] | UnsetValue = unset,
job_executor: str | UnsetValue = unset,
misfire_grace_time: float | timedelta | None | UnsetValue = unset,
max_running_jobs: int | None | UnsetValue = unset,
Expand Down Expand Up @@ -264,7 +264,7 @@ def add_schedule(
trigger: Trigger,
*,
id: str | None = None,
args: Iterable | None = None,
args: Iterable[Any] | None = None,
kwargs: Mapping[str, Any] | None = None,
paused: bool = False,
coalesce: CoalescePolicy = CoalescePolicy.latest,
Expand Down Expand Up @@ -330,7 +330,7 @@ def add_job(
self,
func_or_task_id: TaskType,
*,
args: Iterable | None = None,
args: Iterable[Any] | None = None,
kwargs: Mapping[str, Any] | None = None,
job_executor: str | UnsetValue = unset,
metadata: MetadataType | UnsetValue = unset,
Expand Down Expand Up @@ -361,9 +361,9 @@ def get_job_result(self, job_id: UUID, *, wait: bool = True) -> JobResult | None

def run_job(
self,
func_or_task_id: str | Callable,
func_or_task_id: str | Callable[..., Any],
*,
args: Iterable | None = None,
args: Iterable[Any] | None = None,
kwargs: Mapping[str, Any] | None = None,
job_executor: str | UnsetValue = unset,
metadata: MetadataType | UnsetValue = unset,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pathlib import Path
from queue import Queue
from types import ModuleType
from typing import Any

import anyio
import pytest
Expand Down Expand Up @@ -458,7 +459,7 @@ async def test_run_job(self, raw_datastore: DataStore, success: bool) -> None:
)
async def test_callable_types(
self,
target: Callable,
target: Callable[..., Any],
expected_result: object,
use_scheduling: bool,
raw_datastore: DataStore,
Expand Down

0 comments on commit 1eabad7

Please sign in to comment.