Skip to content

Commit 0c95e71

Browse files
remove event loop detection
1 parent 36958b9 commit 0c95e71

File tree

3 files changed

+4
-31
lines changed

3 files changed

+4
-31
lines changed

docs/source/devel/testloop.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ to an ``async def`` test case.
2121
Async commands
2222
==============
2323

24-
.. autoclass:: PingPong
25-
2624
.. autoclass:: Schedule(*await Any)
2725

2826
.. py:class:: Switch(skip: int, /)

unittests/test_builtins.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import asyncstdlib as a
66

7-
from .utility import sync, asyncify, awaitify, inside_loop
7+
from .utility import sync, asyncify, awaitify
88

99

1010
def hide_coroutine(corofunc):
@@ -83,8 +83,7 @@ async def __aiter__(self):
8383
yield 1
8484
finally:
8585
nonlocal closed
86-
if await inside_loop():
87-
closed = True
86+
closed = True
8887

8988
zip_iter = a.zip(asyncify(range(-5, 0)), SomeIterable())
9089
async for va, vb in zip_iter:

unittests/utility.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from typing import (
22
Callable,
33
Coroutine,
4-
Generator,
54
Iterable,
65
AsyncIterator,
76
TypeVar,
@@ -45,25 +44,6 @@ async def await_wrapper(*args: Any, **kwargs: Any) -> T:
4544
return await_wrapper
4645

4746

48-
class PingPong:
49-
"""
50-
Signal to the event loop which gets returned unchanged
51-
52-
The coroutine yields to the event loop but is resumed
53-
immediately, without running others in the meantime.
54-
This is mainly useful for ensuring the event loop is used.
55-
"""
56-
57-
def __await__(self) -> "Generator[PingPong, Any, Any]":
58-
return (yield self)
59-
60-
61-
async def inside_loop() -> bool:
62-
"""Test whether there is an active event loop available"""
63-
signal = PingPong()
64-
return await signal is signal
65-
66-
6747
class Schedule:
6848
r"""
6949
Signal to the event loop to adopt and run new coroutines
@@ -136,9 +116,7 @@ def sync(test_case: Callable[..., Coroutine[None, Any, Any]], /) -> Callable[...
136116
Mark an ``async def`` test case to be run synchronously with children
137117
138118
This provides a primitive "event loop" which only responds
139-
to the :py:class:`PingPong`, :py:class:`Schedule`, :py:class:`Switch`
140-
and :py:class:`Lock`. This loop is appropriate for tests that need
141-
to check concurrency.
119+
to :py:class:`Schedule`, :py:class:`Switch` and :py:class:`Lock`.
142120
143121
It should be applied as a decorator on an ``async def`` function, which
144122
is then turned into a synchronous callable that will run the ``async def``
@@ -159,9 +137,7 @@ def run_sync(*args: Any, **kwargs: Any):
159137
result = e.args[0] if e.args else None
160138
assert result is None, f"got '{result!r}' expected 'None'"
161139
else:
162-
if isinstance(event, PingPong):
163-
run_queue.appendleft((coro, event))
164-
elif isinstance(event, Schedule):
140+
if isinstance(event, Schedule):
165141
run_queue.extend((new_coro, None) for new_coro in event.coros)
166142
run_queue.append((coro, event))
167143
elif isinstance(event, Switch):

0 commit comments

Comments
 (0)