Skip to content

Type error in pytest-asyncio==0.26.0 with: Value of type variable "_R" of function cannot be "AsyncClient" #1090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jamesbraza opened this issue Apr 8, 2025 · 2 comments
Milestone

Comments

@jamesbraza
Copy link

Upgrading to pytest-asyncio==0.26.0:

import pytest_asyncio
from httpx import AsyncClient


@pytest_asyncio.fixture(scope="function")
def server_async_client() -> AsyncClient: ...

I get this error from mypy:

a.py:5:2: error: Value of type variable "_R" of function cannot be "AsyncClient"  [type-var]
    @pytest_asyncio.fixture(scope="function")
     ^

This is with Python 3.12.7 and the following packages:

httpx                     0.27.2
mypy                      1.15.0
pytest                    8.3.5
pytest-asyncio            0.25.3
@seifertm
Copy link
Contributor

Thanks for reporting this! Could this be a regression of #1045?

@seifertm seifertm added this to the v0.26 milestone Apr 16, 2025
@jamesbraza
Copy link
Author

Yeah correct, that PR binds the "return" TypeVar _R to be awaitable, assuming it's always wrapping an async function.

That assumption is incorrect because it's possible to wrap non-async functions with pytest_asyncio.fixture:

@pytest_asyncio.fixture
def some_int() -> int:
    return 5

An alternate design could be pytest_asyncio.fixture blowing up if not wrapping an async function, as otherwise one should just use a normal pytest.fixture:

@pytest.fixture
def some_int() -> int:
    return 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants