Skip to content

Incorrect typing for set_task_factory #584

@ordinary-jamie

Description

@ordinary-jamie
  • uvloop version: 0.19.0
  • Python version: 3.12.0
  • Platform: 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
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?:
  • Does uvloop behave differently from vanilla asyncio? How?:

For PY311 the task factory will be called with context=context. This isn't typed in the .pyi file correctly

Running mypy with this script will raise an error

# uvloop-task-factory-typing.py
import asyncio

import uvloop


def task_factory(loop, coro, context) -> asyncio.Future:
    return asyncio.Future()


uvloop.Loop().set_task_factory(task_factory)
mypy --version
# mypy 1.7.0 (compiled: yes)

mypy uvloop-task-factory-typing.py 
# uvloop-task-factory-typing.py:11: error: Argument 1 to "set_task_factory" of "Loop" has incompatible type "Callable[[Any, Any, Any], Future[Any]]"; expected "Callable[[AbstractEventLoop, Generator[Any, None, Never]], Future[Never]] | None"  [arg-type]
# Found 1 error in 1 file (checked 1 source file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions