Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 46771 #31415

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions Lib/asyncio/timeouts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import contextlib
import enum

from dataclasses import dataclass
from types import TracebackType
from typing import final, Any, Iterator, Optional, Type

Expand All @@ -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]:
Expand All @@ -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)}>"

Expand Down