Skip to content

Commit 295d543

Browse files
committed
YAPF me harder
1 parent b139658 commit 295d543

6 files changed

Lines changed: 26 additions & 13 deletions

File tree

tests/interop/test_calls.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,37 @@ async def async_gen_to_list(generator):
1616
result.append(item)
1717
return result
1818

19+
1920
class TrioContext:
2021
def __init__(self, parent):
2122
self.parent = parent
23+
2224
async def __aenter__(self):
2325
assert self.parent.did_it == 0
2426
self.parent.did_it = 1
2527
assert sniffio.current_async_library() == "trio"
2628
await trio.sleep(0.01)
2729
self.parent.did_it = 2
2830
return self
31+
2932
async def __aexit__(self, *tb):
3033
assert self.parent.did_it == 3
3134
self.parent.did_it = 4
3235

36+
3337
class AioContext:
3438
def __init__(self, parent, loop):
3539
self.parent = parent
3640
self.loop = loop
41+
3742
async def __aenter__(self):
3843
assert self.parent.did_it == 0
3944
self.parent.did_it = 1
4045
assert sniffio.current_async_library() == "asyncio"
4146
await asyncio.sleep(0.01, loop=self.loop)
4247
self.parent.did_it = 2
4348
return self
49+
4450
async def __aexit__(self, *tb):
4551
assert self.parent.did_it == 3
4652
self.parent.did_it = 4
@@ -99,6 +105,7 @@ async def _call_trio_ctx():
99105
assert self.did_it == 2
100106
self.did_it = 3
101107
assert self.did_it == 4
108+
102109
await loop.run_asyncio(_call_trio_ctx)
103110

104111
@pytest.mark.trio
@@ -333,12 +340,11 @@ async def cancel_soon(nursery):
333340
@pytest.mark.trio
334341
async def test_trio_asyncio_iterator(self, loop):
335342
async def slow_nums():
336-
for n in range(1,6):
343+
for n in range(1, 6):
337344
asyncio.sleep(0.01, loop=loop)
338345
yield n
339346

340-
sum=0
347+
sum = 0
341348
async for n in loop.run_asyncio(slow_nums()):
342349
sum += n
343350
assert sum == 15
344-

tests/python/test_windows_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import asyncio
1313
try:
1414
import _overlapped
15-
except ImportError: # py<3.7
15+
except ImportError: # py<3.7
1616
from asyncio import _overlapped
1717
from .. import utils as test_utils
1818
from asyncio import windows_events

tests/python/test_windows_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
try:
1515
import _overlapped
16-
except ImportError: # py<3.7
16+
except ImportError: # py<3.7
1717
from asyncio import _overlapped
1818
from asyncio import windows_utils
1919
try:

trio_asyncio/adapter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def _allow_asyncio(fn, *args):
7171
if isinstance(coro, asyncio.Future):
7272
return (yield from trio_asyncio.run_future(coro))
7373

74-
p,a = coro.send,None
74+
p, a = coro.send, None
7575
while True:
7676
try:
7777
yielded = p(a)
@@ -83,9 +83,10 @@ def _allow_asyncio(fn, *args):
8383
else:
8484
next_send = yield yielded
8585
except BaseException as exc:
86-
p,a = coro.throw,exc
86+
p, a = coro.throw, exc
8787
else:
88-
p,a = coro.send,next_send
88+
p, a = coro.send, next_send
89+
8990

9091
async def allow_asyncio(fn, *args):
9192
"""
@@ -100,11 +101,10 @@ async def allow_asyncio(fn, *args):
100101
This function must be called from :mod:`trio` context.
101102
"""
102103
shim = trio_asyncio.base._shim_running
103-
if shim.get(): # nested call: skip
104+
if shim.get(): # nested call: skip
104105
return await fn(*args)
105106
token = shim.set(True)
106107
try:
107108
return await _allow_asyncio(fn, *args)
108109
finally:
109110
shim.reset(token)
110-

trio_asyncio/async_.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,3 @@ def _main_loop_exit(self):
128128
nursery.cancel_scope.cancel()
129129
current_loop.reset(old_loop)
130130
current_policy.reset(old_policy)
131-

trio_asyncio/base.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,23 +271,31 @@ def run_asyncio(self, proc, *args):
271271
You can also use this for calling an asyncio-style
272272
async iterator or async context manager.
273273
"""
274+
274275
class t2aWrapper:
275276
def __await__(slf):
276277
f = proc(*args)
277278
return self.run_coroutine(f).__await__()
279+
278280
def __aenter__(slf):
279281
proc_enter = getattr(proc, "__aenter__", None)
280282
if proc_enter is None or args:
281-
raise RuntimeError("Call 'run_asyncio(ctxfactory(*args))', not 'run_asyncio(ctxfactory, *args)'")
283+
raise RuntimeError(
284+
"Call 'run_asyncio(ctxfactory(*args))', not 'run_asyncio(ctxfactory, *args)'"
285+
)
282286
f = proc_enter()
283287
return self.run_coroutine(f)
288+
284289
def __aexit__(slf, *tb):
285290
f = proc.__aexit__(*tb)
286291
return self.run_coroutine(f)
292+
287293
def __aiter__(slf):
288294
proc_iter = getattr(proc, "__anext__", None)
289295
if proc_iter is None or args:
290-
raise RuntimeError("Call 'run_asyncio(gen(*args))', not 'run_asyncio(gen, *args)'")
296+
raise RuntimeError(
297+
"Call 'run_asyncio(gen(*args))', not 'run_asyncio(gen, *args)'"
298+
)
291299
return run_generator(self, proc)
292300

293301
return t2aWrapper()

0 commit comments

Comments
 (0)