Skip to content

Commit

Permalink
Revert "de-loop=loop-ification required for for Python 3.10+"
Browse files Browse the repository at this point in the history
This reverts (cherry-picked) commits 8930bf2 and d1051b0.

We will do the de-`loop=`-ification in PR python-trio#94.
  • Loading branch information
shamrin committed Jan 5, 2021
1 parent d1051b0 commit bcd5ab8
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions tests/aiotest/test_coroutine.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
async def hello_world(asyncio, result, delay, loop):
result.append("Hello")
# retrieve the event loop from the policy
await asyncio.sleep(delay)
await asyncio.sleep(delay, loop=loop)
result.append('World')
return "."

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

@pytest.mark.trio
Expand All @@ -37,7 +37,7 @@ async def run_hello_world(self, loop, config):
@pytest.mark.trio
async def test_waiter(self, loop, config):
async def waiter(asyncio, hello_world, result):
fut = asyncio.Future()
fut = asyncio.Future(loop=loop)
loop.call_soon(fut.set_result, "Future")

value = await fut
Expand Down
14 changes: 7 additions & 7 deletions tests/interop/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,25 @@ async def dly_asyncio_depr(self):
async def dly_asyncio_adapted(self):
if sys.version_info >= (3, 7):
assert sniffio.current_async_library() == "asyncio"
await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop)
self.flag |= 1
return 4

async def dly_asyncio(self, do_test=True):
if do_test and sys.version_info >= (3, 7):
assert sniffio.current_async_library() == "asyncio"
await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop)
self.flag |= 1
return 4

async def iter_asyncio(self, do_test=True):
if do_test and sys.version_info >= (3, 7):
assert sniffio.current_async_library() == "asyncio"
await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop)
yield 1
await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop)
yield 2
await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop)
self.flag |= 1

async def iter_trio(self):
Expand All @@ -98,10 +98,10 @@ async def iter_trio(self):

@asynccontextmanager
async def ctx_asyncio(self):
await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop)
self.flag |= 1
yield self
await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop)
self.flag |= 2

@asynccontextmanager
Expand Down
26 changes: 13 additions & 13 deletions tests/interop/test_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def __aenter__(self):
self.parent.did_it = 1
if sys.version_info >= (3, 7):
assert sniffio.current_async_library() == "asyncio"
await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop)
self.parent.did_it = 2
return self

Expand Down Expand Up @@ -83,7 +83,7 @@ async def call_a_ts(self, proc, *args, loop=None):
@pytest.mark.trio
async def test_call_at(self, loop):
async def delay(t):
done = asyncio.Event()
done = asyncio.Event(loop=loop)
loop.call_at(t, done.set)
await done.wait()

Expand Down Expand Up @@ -193,7 +193,7 @@ def dly_trio(seen):
@pytest.mark.trio
async def test_trio_asyncio(self, loop):
async def dly_asyncio(seen):
await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=loop)
seen.flag |= 1
return 4

Expand Down Expand Up @@ -280,7 +280,7 @@ def err_trio_sync():
@pytest.mark.trio
async def test_trio_asyncio_error(self, loop):
async def err_asyncio():
await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=loop)
raise RuntimeError("I has an owie")

with pytest.raises(RuntimeError) as err:
Expand Down Expand Up @@ -317,14 +317,14 @@ async def cancelled_trio(seen):
async def test_trio_asyncio_cancel_out(self, loop):
async def cancelled_asyncio(seen):
seen.flag |= 1
await asyncio.sleep(0.01)
f = asyncio.Future()
await asyncio.sleep(0.01, loop=loop)
f = asyncio.Future(loop=loop)
f.cancel()
return f.result() # raises error

def cancelled_future(seen):
seen.flag |= 1
f = asyncio.Future()
f = asyncio.Future(loop=loop)
f.cancel()
return f # contains error

Expand Down Expand Up @@ -387,7 +387,7 @@ async def in_trio(started, seen):
seen.flag |= 2

async def cancel_asyncio(seen):
started = asyncio.Event()
started = asyncio.Event(loop=loop)
f = asyncio.ensure_future(self.call_a_t(in_trio, started, seen, loop=loop))
await started.wait()
f.cancel()
Expand All @@ -404,7 +404,7 @@ async def test_trio_asyncio_cancel_in(self, loop):
async def in_asyncio(started, seen):
started.set()
try:
await asyncio.sleep(9999)
await asyncio.sleep(9999, loop=loop)
except asyncio.CancelledError:
seen.flag |= 1
except trio.Cancelled:
Expand Down Expand Up @@ -527,7 +527,7 @@ def err_asyncio():
async def test_trio_asyncio_generator(self, loop):
async def dly_asyncio():
yield 1
await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=loop)
yield 2

with test_utils.deprecate(self):
Expand Down Expand Up @@ -557,7 +557,7 @@ async def cancel_soon(nursery):
await trio.sleep(0.01)
nursery.cancel_scope.cancel()

hold = asyncio.Event()
hold = asyncio.Event(loop=loop)
seen = Seen()

with test_utils.deprecate(self):
Expand All @@ -571,7 +571,7 @@ async def cancel_soon(nursery):
async def test_trio_asyncio_iterator(self, loop):
async def slow_nums():
for n in range(1, 6):
await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=loop)
yield n

sum = 0
Expand All @@ -583,7 +583,7 @@ async def slow_nums():
async def test_trio_asyncio_iterator_depr(self, loop):
async def slow_nums():
for n in range(1, 6):
await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=loop)
yield n

sum = 0
Expand Down
8 changes: 4 additions & 4 deletions tests/test_aio_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class MySubprocessProtocol(asyncio.SubprocessProtocol):
def __init__(self, loop):
self.state = 'INITIAL'
self.transport = None
self.connected = asyncio.Future()
self.completed = asyncio.Future()
self.disconnects = {fd: asyncio.Future() for fd in range(3)}
self.connected = asyncio.Future(loop=loop)
self.completed = asyncio.Future(loop=loop)
self.disconnects = {fd: asyncio.Future(loop=loop) for fd in range(3)}
self.data = {1: b'', 2: b''}
self.returncode = None
self.got_data = {1: asyncio.Event(), 2: asyncio.Event()}
self.got_data = {1: asyncio.Event(loop=loop), 2: asyncio.Event(loop=loop)}

def connection_made(self, transport):
self.transport = transport
Expand Down
4 changes: 2 additions & 2 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ def do_not_run():

async def cancel_sleep():
h = loop.call_later(0.2, do_not_run)
await asyncio.sleep(0.1)
await asyncio.sleep(0.1, loop=loop)
h.cancel()
await asyncio.sleep(0.3)
await asyncio.sleep(0.3, loop=loop)

await trio_asyncio.aio_as_trio(cancel_sleep, loop=loop)()
assert owch == 0
Expand Down
2 changes: 1 addition & 1 deletion trio_asyncio/_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ async def allow_asyncio(fn, *args):
import trio_asyncio
async def hello(loop):
await asyncio.sleep(1)
await asyncio.sleep(1, loop=loop)
print("Hello")
await trio.sleep(1)
print("World")
Expand Down
2 changes: 1 addition & 1 deletion trio_asyncio/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def abort_cb(raise_cancel_arg):
try:
while True:
# Schedule in asyncio that we read the next item from the iterator
current_read = asyncio.ensure_future(consume_next())
current_read = asyncio.ensure_future(consume_next(), loop=loop)

item = await trio.lowlevel.wait_task_rescheduled(abort_cb)

Expand Down

0 comments on commit bcd5ab8

Please sign in to comment.