Skip to content

Commit 45b1db9

Browse files
authored
use _LoopBoundMixin in asyncio when appropriate (#11127)
related to #3968
1 parent 6b9f82d commit 45b1db9

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

stdlib/asyncio/locks.pyi

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ from typing_extensions import Literal, Self
1010
from .events import AbstractEventLoop
1111
from .futures import Future
1212

13-
if sys.version_info >= (3, 11):
13+
if sys.version_info >= (3, 10):
1414
from .mixins import _LoopBoundMixin
15+
else:
16+
_LoopBoundMixin = object
1517

1618
if sys.version_info >= (3, 11):
1719
__all__ = ("Lock", "Event", "Condition", "Semaphore", "BoundedSemaphore", "Barrier")
@@ -44,7 +46,7 @@ else:
4446
self, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None
4547
) -> None: ...
4648

47-
class Lock(_ContextManagerMixin):
49+
class Lock(_ContextManagerMixin, _LoopBoundMixin):
4850
if sys.version_info >= (3, 10):
4951
def __init__(self) -> None: ...
5052
else:
@@ -54,7 +56,7 @@ class Lock(_ContextManagerMixin):
5456
async def acquire(self) -> Literal[True]: ...
5557
def release(self) -> None: ...
5658

57-
class Event:
59+
class Event(_LoopBoundMixin):
5860
if sys.version_info >= (3, 10):
5961
def __init__(self) -> None: ...
6062
else:
@@ -65,7 +67,7 @@ class Event:
6567
def clear(self) -> None: ...
6668
async def wait(self) -> Literal[True]: ...
6769

68-
class Condition(_ContextManagerMixin):
70+
class Condition(_ContextManagerMixin, _LoopBoundMixin):
6971
if sys.version_info >= (3, 10):
7072
def __init__(self, lock: Lock | None = None) -> None: ...
7173
else:
@@ -79,7 +81,7 @@ class Condition(_ContextManagerMixin):
7981
def notify(self, n: int = 1) -> None: ...
8082
def notify_all(self) -> None: ...
8183

82-
class Semaphore(_ContextManagerMixin):
84+
class Semaphore(_ContextManagerMixin, _LoopBoundMixin):
8385
_value: int
8486
_waiters: deque[Future[Any]]
8587
if sys.version_info >= (3, 10):

stdlib/asyncio/queues.pyi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@ from typing import Any, Generic, TypeVar
55
if sys.version_info >= (3, 9):
66
from types import GenericAlias
77

8+
if sys.version_info >= (3, 10):
9+
from .mixins import _LoopBoundMixin
10+
else:
11+
_LoopBoundMixin = object
12+
813
__all__ = ("Queue", "PriorityQueue", "LifoQueue", "QueueFull", "QueueEmpty")
914

1015
class QueueEmpty(Exception): ...
1116
class QueueFull(Exception): ...
1217

1318
_T = TypeVar("_T")
1419

15-
class Queue(Generic[_T]):
20+
# If Generic[_T] is last and _LoopBoundMixin is object, pyright is unhappy.
21+
# We can remove the noqa pragma when dropping 3.9 support.
22+
class Queue(Generic[_T], _LoopBoundMixin): # noqa: Y059
1623
if sys.version_info >= (3, 10):
1724
def __init__(self, maxsize: int = 0) -> None: ...
1825
else:

0 commit comments

Comments
 (0)