From fbba91c01716fe40588fc41c00f66aacc4754cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tin=20Tvrtkovi=C4=87?= Date: Fri, 18 Feb 2022 19:57:42 +0100 Subject: [PATCH 1/2] Fix CancelScope repr --- Lib/asyncio/timeouts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/asyncio/timeouts.py b/Lib/asyncio/timeouts.py index b841e477df9c46..22b9cde75f8655 100644 --- a/Lib/asyncio/timeouts.py +++ b/Lib/asyncio/timeouts.py @@ -63,7 +63,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)}>" From 18e4268447b6ba40ead9cac01be9f8559c66cf21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tin=20Tvrtkovi=C4=87?= Date: Fri, 18 Feb 2022 23:30:38 +0100 Subject: [PATCH 2/2] CancelScope to dataclass --- Lib/asyncio/timeouts.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Lib/asyncio/timeouts.py b/Lib/asyncio/timeouts.py index 22b9cde75f8655..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]: 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