Skip to content

Commit bcd5ab8

Browse files
committed
Revert "de-loop=loop-ification required for for Python 3.10+"
This reverts (cherry-picked) commits 8930bf2 and d1051b0. We will do the de-`loop=`-ification in PR python-trio#94.
1 parent d1051b0 commit bcd5ab8

File tree

7 files changed

+31
-31
lines changed

7 files changed

+31
-31
lines changed

tests/aiotest/test_coroutine.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
async def hello_world(asyncio, result, delay, loop):
88
result.append("Hello")
99
# retrieve the event loop from the policy
10-
await asyncio.sleep(delay)
10+
await asyncio.sleep(delay, loop=loop)
1111
result.append('World')
1212
return "."
1313

@@ -17,7 +17,7 @@ class TestCoroutine(aiotest.TestCase):
1717
async def test_hello_world(self, loop, config):
1818
result = []
1919
coro = hello_world(config.asyncio, result, 0.001, loop)
20-
await loop.run_aio_coroutine(config.asyncio.ensure_future(coro))
20+
await loop.run_aio_coroutine(config.asyncio.ensure_future(coro, loop=loop))
2121
assert result == ['Hello', 'World']
2222

2323
@pytest.mark.trio
@@ -37,7 +37,7 @@ async def run_hello_world(self, loop, config):
3737
@pytest.mark.trio
3838
async def test_waiter(self, loop, config):
3939
async def waiter(asyncio, hello_world, result):
40-
fut = asyncio.Future()
40+
fut = asyncio.Future(loop=loop)
4141
loop.call_soon(fut.set_result, "Future")
4242

4343
value = await fut

tests/interop/test_adapter.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,25 @@ async def dly_asyncio_depr(self):
6565
async def dly_asyncio_adapted(self):
6666
if sys.version_info >= (3, 7):
6767
assert sniffio.current_async_library() == "asyncio"
68-
await asyncio.sleep(0.01)
68+
await asyncio.sleep(0.01, loop=self.loop)
6969
self.flag |= 1
7070
return 4
7171

7272
async def dly_asyncio(self, do_test=True):
7373
if do_test and sys.version_info >= (3, 7):
7474
assert sniffio.current_async_library() == "asyncio"
75-
await asyncio.sleep(0.01)
75+
await asyncio.sleep(0.01, loop=self.loop)
7676
self.flag |= 1
7777
return 4
7878

7979
async def iter_asyncio(self, do_test=True):
8080
if do_test and sys.version_info >= (3, 7):
8181
assert sniffio.current_async_library() == "asyncio"
82-
await asyncio.sleep(0.01)
82+
await asyncio.sleep(0.01, loop=self.loop)
8383
yield 1
84-
await asyncio.sleep(0.01)
84+
await asyncio.sleep(0.01, loop=self.loop)
8585
yield 2
86-
await asyncio.sleep(0.01)
86+
await asyncio.sleep(0.01, loop=self.loop)
8787
self.flag |= 1
8888

8989
async def iter_trio(self):
@@ -98,10 +98,10 @@ async def iter_trio(self):
9898

9999
@asynccontextmanager
100100
async def ctx_asyncio(self):
101-
await asyncio.sleep(0.01)
101+
await asyncio.sleep(0.01, loop=self.loop)
102102
self.flag |= 1
103103
yield self
104-
await asyncio.sleep(0.01)
104+
await asyncio.sleep(0.01, loop=self.loop)
105105
self.flag |= 2
106106

107107
@asynccontextmanager

tests/interop/test_calls.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def __aenter__(self):
4848
self.parent.did_it = 1
4949
if sys.version_info >= (3, 7):
5050
assert sniffio.current_async_library() == "asyncio"
51-
await asyncio.sleep(0.01)
51+
await asyncio.sleep(0.01, loop=self.loop)
5252
self.parent.did_it = 2
5353
return self
5454

@@ -83,7 +83,7 @@ async def call_a_ts(self, proc, *args, loop=None):
8383
@pytest.mark.trio
8484
async def test_call_at(self, loop):
8585
async def delay(t):
86-
done = asyncio.Event()
86+
done = asyncio.Event(loop=loop)
8787
loop.call_at(t, done.set)
8888
await done.wait()
8989

@@ -193,7 +193,7 @@ def dly_trio(seen):
193193
@pytest.mark.trio
194194
async def test_trio_asyncio(self, loop):
195195
async def dly_asyncio(seen):
196-
await asyncio.sleep(0.01)
196+
await asyncio.sleep(0.01, loop=loop)
197197
seen.flag |= 1
198198
return 4
199199

@@ -280,7 +280,7 @@ def err_trio_sync():
280280
@pytest.mark.trio
281281
async def test_trio_asyncio_error(self, loop):
282282
async def err_asyncio():
283-
await asyncio.sleep(0.01)
283+
await asyncio.sleep(0.01, loop=loop)
284284
raise RuntimeError("I has an owie")
285285

286286
with pytest.raises(RuntimeError) as err:
@@ -317,14 +317,14 @@ async def cancelled_trio(seen):
317317
async def test_trio_asyncio_cancel_out(self, loop):
318318
async def cancelled_asyncio(seen):
319319
seen.flag |= 1
320-
await asyncio.sleep(0.01)
321-
f = asyncio.Future()
320+
await asyncio.sleep(0.01, loop=loop)
321+
f = asyncio.Future(loop=loop)
322322
f.cancel()
323323
return f.result() # raises error
324324

325325
def cancelled_future(seen):
326326
seen.flag |= 1
327-
f = asyncio.Future()
327+
f = asyncio.Future(loop=loop)
328328
f.cancel()
329329
return f # contains error
330330

@@ -387,7 +387,7 @@ async def in_trio(started, seen):
387387
seen.flag |= 2
388388

389389
async def cancel_asyncio(seen):
390-
started = asyncio.Event()
390+
started = asyncio.Event(loop=loop)
391391
f = asyncio.ensure_future(self.call_a_t(in_trio, started, seen, loop=loop))
392392
await started.wait()
393393
f.cancel()
@@ -404,7 +404,7 @@ async def test_trio_asyncio_cancel_in(self, loop):
404404
async def in_asyncio(started, seen):
405405
started.set()
406406
try:
407-
await asyncio.sleep(9999)
407+
await asyncio.sleep(9999, loop=loop)
408408
except asyncio.CancelledError:
409409
seen.flag |= 1
410410
except trio.Cancelled:
@@ -527,7 +527,7 @@ def err_asyncio():
527527
async def test_trio_asyncio_generator(self, loop):
528528
async def dly_asyncio():
529529
yield 1
530-
await asyncio.sleep(0.01)
530+
await asyncio.sleep(0.01, loop=loop)
531531
yield 2
532532

533533
with test_utils.deprecate(self):
@@ -557,7 +557,7 @@ async def cancel_soon(nursery):
557557
await trio.sleep(0.01)
558558
nursery.cancel_scope.cancel()
559559

560-
hold = asyncio.Event()
560+
hold = asyncio.Event(loop=loop)
561561
seen = Seen()
562562

563563
with test_utils.deprecate(self):
@@ -571,7 +571,7 @@ async def cancel_soon(nursery):
571571
async def test_trio_asyncio_iterator(self, loop):
572572
async def slow_nums():
573573
for n in range(1, 6):
574-
await asyncio.sleep(0.01)
574+
await asyncio.sleep(0.01, loop=loop)
575575
yield n
576576

577577
sum = 0
@@ -583,7 +583,7 @@ async def slow_nums():
583583
async def test_trio_asyncio_iterator_depr(self, loop):
584584
async def slow_nums():
585585
for n in range(1, 6):
586-
await asyncio.sleep(0.01)
586+
await asyncio.sleep(0.01, loop=loop)
587587
yield n
588588

589589
sum = 0

tests/test_aio_subprocess.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class MySubprocessProtocol(asyncio.SubprocessProtocol):
2020
def __init__(self, loop):
2121
self.state = 'INITIAL'
2222
self.transport = None
23-
self.connected = asyncio.Future()
24-
self.completed = asyncio.Future()
25-
self.disconnects = {fd: asyncio.Future() for fd in range(3)}
23+
self.connected = asyncio.Future(loop=loop)
24+
self.completed = asyncio.Future(loop=loop)
25+
self.disconnects = {fd: asyncio.Future(loop=loop) for fd in range(3)}
2626
self.data = {1: b'', 2: b''}
2727
self.returncode = None
28-
self.got_data = {1: asyncio.Event(), 2: asyncio.Event()}
28+
self.got_data = {1: asyncio.Event(loop=loop), 2: asyncio.Event(loop=loop)}
2929

3030
def connection_made(self, transport):
3131
self.transport = transport

tests/test_misc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ def do_not_run():
263263

264264
async def cancel_sleep():
265265
h = loop.call_later(0.2, do_not_run)
266-
await asyncio.sleep(0.1)
266+
await asyncio.sleep(0.1, loop=loop)
267267
h.cancel()
268-
await asyncio.sleep(0.3)
268+
await asyncio.sleep(0.3, loop=loop)
269269

270270
await trio_asyncio.aio_as_trio(cancel_sleep, loop=loop)()
271271
assert owch == 0

trio_asyncio/_adapter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ async def allow_asyncio(fn, *args):
271271
import trio_asyncio
272272
273273
async def hello(loop):
274-
await asyncio.sleep(1)
274+
await asyncio.sleep(1, loop=loop)
275275
print("Hello")
276276
await trio.sleep(1)
277277
print("World")

trio_asyncio/_util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def abort_cb(raise_cancel_arg):
108108
try:
109109
while True:
110110
# Schedule in asyncio that we read the next item from the iterator
111-
current_read = asyncio.ensure_future(consume_next())
111+
current_read = asyncio.ensure_future(consume_next(), loop=loop)
112112

113113
item = await trio.lowlevel.wait_task_rescheduled(abort_cb)
114114

0 commit comments

Comments
 (0)