Skip to content

Commit ae6c95f

Browse files
committed
Python: Fix asyncio.coroutine deprecation
Was removed in 3.11, see https://docs.python.org/3.10/library/asyncio-task.html#asyncio.coroutine I couldn't make the __awwait__ actually give the result to the agen function... I also tried looking into https://docs.python.org/3/library/types.html#types.coroutine, but also failed to make that work. Without the Future, such as doing `yield SOURCE` inside `__await__` it complains `RuntimeError: Task got bad yield: 'source'`
1 parent 4256fbf commit ae6c95f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

python/ql/test/experimental/dataflow/coverage/datamodel.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,20 @@ async def coro(x):
186186
class A:
187187

188188
def __await__(self):
189-
# yield SOURCE -- see https://groups.google.com/g/dev-python/c/_lrrc-vp9TI?pli=1
190-
return (yield from asyncio.coroutine(lambda: SOURCE)())
189+
fut = asyncio.Future()
190+
fut.set_result(SOURCE)
191+
yield from fut
191192

192-
async def agen(x):
193+
async def atest_custom_await_impl():
193194
a = A()
194-
return await a
195+
x = await a
196+
# TODO: Figure out how to actually return something from our custom __await__
197+
# implementation. The problem is we have to play nicely with the asyncio framework,
198+
# which have their own expectations on what a return value from __await__ should look
199+
# like.
200+
assert x is None
201+
SINK_F(x)
195202

196-
SINK(asyncio.run(agen(SOURCE))) # $ MISSING: flow
197203

198204
# Asynchronous generator functions
199205
# A function or method which is defined using async def and which uses the yield statement is called a asynchronous generator function. Such a function, when called, returns an asynchronous iterator object which can be used in an async for statement to execute the body of the function.

0 commit comments

Comments
 (0)