summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2021-09-06 00:34:22 +0300
committerAlex Grönholm <alex.gronholm@nextday.fi>2021-09-06 01:39:07 +0300
commitd5fbe437a4481bdd07085bc3658392a181d2c6a6 (patch)
treeda75fd3091f7afd3b6b25b31d27b2f57b7e1043a
parentda94af0571e6c40553b4463b5fba1d94f598b136 (diff)
downloadapscheduler-d5fbe437a4481bdd07085bc3658392a181d2c6a6.tar.gz
Fixed a number of mypy errors
-rw-r--r--src/apscheduler/datastores/async_/sqlalchemy.py6
-rw-r--r--src/apscheduler/datastores/async_/sync_adapter.py2
-rw-r--r--src/apscheduler/datastores/sync/sqlalchemy.py4
-rw-r--r--src/apscheduler/schedulers/async_.py5
-rw-r--r--src/apscheduler/util.py26
5 files changed, 23 insertions, 20 deletions
diff --git a/src/apscheduler/datastores/async_/sqlalchemy.py b/src/apscheduler/datastores/async_/sqlalchemy.py
index c3d1ff1..b0c8afa 100644
--- a/src/apscheduler/datastores/async_/sqlalchemy.py
+++ b/src/apscheduler/datastores/async_/sqlalchemy.py
@@ -514,7 +514,7 @@ class SQLAlchemyDataStore(AsyncDataStore):
where(self.t_tasks.c.max_running_jobs.isnot(None),
self.t_tasks.c.id.in_(task_ids))
result = await conn.execute(query)
- job_slots_left = dict(result.fetchall())
+ job_slots_left: dict[str, int] = dict(result.fetchall())
# Filter out jobs that don't have free slots
acquired_jobs: list[Job] = []
@@ -539,8 +539,8 @@ class SQLAlchemyDataStore(AsyncDataStore):
await conn.execute(update)
# Increment the running job counters on each task
- p_id = bindparam('p_id')
- p_increment = bindparam('p_increment')
+ p_id: BindParameter = bindparam('p_id')
+ p_increment: BindParameter = bindparam('p_increment')
params = [{'p_id': task_id, 'p_increment': increment}
for task_id, increment in increments.items()]
update = self.t_tasks.update().\
diff --git a/src/apscheduler/datastores/async_/sync_adapter.py b/src/apscheduler/datastores/async_/sync_adapter.py
index fb384a1..51b15d5 100644
--- a/src/apscheduler/datastores/async_/sync_adapter.py
+++ b/src/apscheduler/datastores/async_/sync_adapter.py
@@ -18,7 +18,7 @@ from ...util import reentrant
@reentrant
-@attr.define
+@attr.define(eq=False)
class AsyncDataStoreAdapter(AsyncDataStore):
original: DataStore
_portal: BlockingPortal = attr.field(init=False, eq=False)
diff --git a/src/apscheduler/datastores/sync/sqlalchemy.py b/src/apscheduler/datastores/sync/sqlalchemy.py
index 2465b36..7c30e16 100644
--- a/src/apscheduler/datastores/sync/sqlalchemy.py
+++ b/src/apscheduler/datastores/sync/sqlalchemy.py
@@ -451,8 +451,8 @@ class SQLAlchemyDataStore(DataStore):
conn.execute(update)
# Increment the running job counters on each task
- p_id = bindparam('p_id')
- p_increment = bindparam('p_increment')
+ p_id: BindParameter = bindparam('p_id')
+ p_increment: BindParameter = bindparam('p_increment')
params = [{'p_id': task_id, 'p_increment': increment}
for task_id, increment in increments.items()]
update = self.t_tasks.update().\
diff --git a/src/apscheduler/schedulers/async_.py b/src/apscheduler/schedulers/async_.py
index abbe257..f40414c 100644
--- a/src/apscheduler/schedulers/async_.py
+++ b/src/apscheduler/schedulers/async_.py
@@ -9,8 +9,7 @@ from typing import Any, Callable, Iterable, Mapping, Optional, Type
from uuid import uuid4
import anyio
-from anyio import (
- TASK_STATUS_IGNORED, Event, create_task_group, get_cancelled_exc_class, move_on_after)
+from anyio import TASK_STATUS_IGNORED, create_task_group, get_cancelled_exc_class, move_on_after
from anyio.abc import TaskGroup
from ..abc import AsyncDataStore, DataStore, EventSource, Job, Schedule, Trigger
@@ -18,7 +17,7 @@ from ..datastores.async_.sync_adapter import AsyncDataStoreAdapter
from ..datastores.sync.memory import MemoryDataStore
from ..enums import CoalescePolicy, ConflictPolicy, RunState
from ..events import (
- AsyncEventHub, ScheduleAdded, SchedulerStarted, SchedulerStopped, ScheduleUpdated,
+ AsyncEventHub, Event, ScheduleAdded, SchedulerStarted, SchedulerStopped, ScheduleUpdated,
SubscriptionToken)
from ..marshalling import callable_to_ref
from ..structures import Task
diff --git a/src/apscheduler/util.py b/src/apscheduler/util.py
index 867c15a..d8f40b0 100644
--- a/src/apscheduler/util.py
+++ b/src/apscheduler/util.py
@@ -1,5 +1,8 @@
"""This module contains several handy functions primarily meant for internal use."""
+from __future__ import annotations
+
import sys
+from collections import defaultdict
from datetime import datetime, tzinfo
from typing import Callable, TypeVar
@@ -40,34 +43,35 @@ def reentrant(cls: T_Type) -> T_Type:
the ``__enter__()`` method on the first entry and ``__exit__()`` on the last exit.
"""
- cls._loans = 0
def __enter__(self):
- self._loans += 1
- if self._loans == 1:
+ loans[self] += 1
+ if loans[self] == 1:
previous_enter(self)
return self
def __exit__(self, exc_type, exc_val, exc_tb):
- assert self._loans
- self._loans -= 1
- if self._loans == 0:
+ assert loans[self]
+ loans[self] -= 1
+ if loans[self] == 0:
return previous_exit(self, exc_type, exc_val, exc_tb)
async def __aenter__(self):
- self._loans += 1
- if self._loans == 1:
+ loans[self] += 1
+ if loans[self] == 1:
await previous_aenter(self)
return self
async def __aexit__(self, exc_type, exc_val, exc_tb):
- assert self._loans
- self._loans -= 1
- if self._loans == 0:
+ assert loans[self]
+ loans[self] -= 1
+ if loans[self] == 0:
+ del loans[self]
return await previous_aexit(self, exc_type, exc_val, exc_tb)
+ loans: dict[T_Type, int] = defaultdict(lambda: 0)
previous_enter: Callable = getattr(cls, '__enter__', None)
previous_exit: Callable = getattr(cls, '__exit__', None)
previous_aenter: Callable = getattr(cls, '__aenter__', None)