diff --git a/Lib/asyncio/timeouts.py b/Lib/asyncio/timeouts.py index b841e477df9c46..4c1f0b6c9e1059 100644 --- a/Lib/asyncio/timeouts.py +++ b/Lib/asyncio/timeouts.py @@ -1,6 +1,7 @@ import contextlib import enum +from dataclasses import dataclass from types import TracebackType from typing import final, Any, Iterator, Optional, Type @@ -27,18 +28,13 @@ class _State(enum.Enum): @final +@dataclass(slots=True) class CancelScope: - __slots__ = ("_deadline", "_loop", "_state", "_task", "_timeout_handler") - - def __init__( - self, deadline: Optional[float], loop: events.AbstractEventLoop - ) -> None: - self._loop = loop - self._state = _State.CREATED - - self._timeout_handler: Optional[events.TimerHandle] = None - self._task: Optional[tasks.Task[Any]] = None - self._deadline = deadline + _deadline: float | None + _loop: events.AbstractEventLoop + _state: _State = _State.CREATED + _task: tasks.Task[Any] | None = None + _timeout_handler: events.TimerHandle | None = None @property def deadline(self) -> Optional[float]: @@ -63,7 +59,7 @@ def cancelling(self) -> bool: def __repr__(self) -> str: info = [str(self._state)] if self._state == _State.ENTERED and self._deadline is not None: - info.append("deadline={self._deadline}") + info.append(f"deadline={self._deadline}") cls_name = self.__class__.__name__ return f"<{cls_name} at {id(self):#x}, {' '.join(info)}>" pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy