diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3cb34c3a55..424fc9edd1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,6 +3,7 @@ repos: rev: v0.15.2 hooks: - id: ruff-check + # args: [--fix] - repo: https://github.com/psf/black-pre-commit-mirror rev: 26.3.1 hooks: diff --git a/distributed/actor.py b/distributed/actor.py index 6ea45ce102..28d9fb59e0 100644 --- a/distributed/actor.py +++ b/distributed/actor.py @@ -245,6 +245,8 @@ class BaseActorFuture(abc.ABC, Awaitable[_T]): Actor """ + __slots__ = () + @abc.abstractmethod def result(self, timeout: str | timedelta | float | None = None) -> _T: ... @@ -255,7 +257,7 @@ def __repr__(self) -> Literal[""]: return "" -@dataclass(frozen=True, eq=False) +@dataclass(frozen=True, eq=False, slots=True) class EagerActorFuture(BaseActorFuture[_T]): """Future to an actor's method call when an actor calls another actor on the same worker""" @@ -272,7 +274,7 @@ def done(self) -> Literal[True]: return True -@dataclass(frozen=True, eq=False) +@dataclass(frozen=True, eq=False, slots=True) class _OK(Generic[_T]): _v: _T @@ -280,7 +282,7 @@ def unwrap(self) -> _T: return self._v -@dataclass(frozen=True, eq=False) +@dataclass(frozen=True, eq=False, slots=True) class _Error: _e: Exception @@ -289,10 +291,16 @@ def unwrap(self) -> NoReturn: class ActorFuture(BaseActorFuture[_T]): + _io_loop: IOLoop + _event: LateLoopEvent + _out: _Error | _OK[_T] | None + + __slots__ = tuple(__annotations__) + def __init__(self, io_loop: IOLoop): self._io_loop = io_loop self._event = LateLoopEvent() - self._out: _Error | _OK[_T] | None = None + self._out = None def __await__(self) -> Generator[object, None, _T]: return self._result().__await__() diff --git a/distributed/metrics.py b/distributed/metrics.py index e27345c81d..ee28a2a7af 100755 --- a/distributed/metrics.py +++ b/distributed/metrics.py @@ -113,12 +113,11 @@ def resync(self) -> None: thread_time = process_time -@dataclass +@dataclass(slots=True) class MeterOutput: start: float stop: float delta: float - __slots__ = tuple(__annotations__) @contextmanager diff --git a/distributed/scheduler.py b/distributed/scheduler.py index 2aac52c663..ace360d093 100644 --- a/distributed/scheduler.py +++ b/distributed/scheduler.py @@ -2,7 +2,6 @@ import asyncio import contextlib -import dataclasses import heapq import inspect import itertools @@ -31,6 +30,7 @@ Set, ) from contextlib import suppress +from dataclasses import dataclass from functools import partial from typing import ( TYPE_CHECKING, @@ -858,7 +858,7 @@ def occupancy(self) -> float: ) -@dataclasses.dataclass +@dataclass(slots=True) class ErredTask: """Lightweight representation of an erred task without any dependency information or runspec. @@ -868,7 +868,7 @@ class ErredTask: TaskState """ - key: Hashable + key: Key timestamp: float erred_on: set[str] exception_text: str diff --git a/distributed/worker_state_machine.py b/distributed/worker_state_machine.py index f0264ec368..3ae0d16e9b 100644 --- a/distributed/worker_state_machine.py +++ b/distributed/worker_state_machine.py @@ -382,6 +382,8 @@ class _InstructionMatch: cls: type[Instruction] kwargs: dict[str, Any] + __slots__ = ("cls", "kwargs") + def __init__(self, cls: type[Instruction], **kwargs: Any): self.cls = cls self.kwargs = kwargs