Closed ordinary-jamie closed 11 months ago
Sorry, my mistake -- mypy
won't raise an error if context
is a kwarg with a default value.
Notwithstanding, is it worth updating the typing to let users know that either a context
kwarg or a unpacked **kwargs
is required on the task factory?
Using just a 2-arg task factory as the type hints currently suggest will raise an error
import asyncio
import uvloop
async def foo():
return "bar"
def main():
loop = uvloop.new_event_loop()
def task_factory(loop, coro):
return asyncio.Task(coro, loop=loop)
loop.set_task_factory(task_factory)
loop.run_until_complete(foo())
main()
TypeError: main.<locals>.task_factory() got an unexpected keyword argument 'context'
sys:1: RuntimeWarning: coroutine 'foo' was never awaited
Darwin 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:32:52 PDT 2023; root:xnu 10002.41.9~7/RELEASE_ARM64_T8122 arm64
PYTHONASYNCIODEBUG
in env?:For
PY311
the task factory will be called withcontext=context
. This isn't typed in the.pyi
file correctlyRunning
mypy
with this script will raise an error