Skip to content
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

Incompatible type when using asynccontextmanager and ParamSpec in generics. #12806

Closed
matiuszka opened this issue May 18, 2022 · 1 comment
Closed
Labels
bug mypy got something wrong

Comments

@matiuszka
Copy link

Bug Report

Usage of asynccontexmanager together with ParamSpec casues mypy errors.

To Reproduce

from contextlib import asynccontextmanager
from dataclasses import dataclass
from typing import (
    AsyncContextManager,
    AsyncIterator,
    Callable,
    Generic,
    ParamSpec,
    TypeVar,
)

_Input = ParamSpec("_Input")
_Result = TypeVar("_Result")


@dataclass
class Foo(Generic[_Input, _Result]):
    func: Callable[_Input, AsyncContextManager[_Result]]

    @asynccontextmanager
    async def boo(
        self, *args: _Input.args, **kwargs: _Input.kwargs
    ) -> AsyncIterator[_Result]:
        async with self.func(*args, **kwargs) as fr:
            yield fr

Actual Behavior

Error:

error: Argument 1 to "asynccontextmanager" has incompatible type "Callable[[Arg(Foo[_Input, _Result], 'self'), **_Input], AsyncIterator[_Result]]"; expected "Callable[[Arg(Foo[_Input, _Result], 'self'), **_Input], AsyncIterator[_Result]]"

Environment

Mypy version: 0.950
Python version: 3.10.3

@erictraut
Copy link

This bug appears to have been fixed in mypy 1.2.0.

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

No branches or pull requests

3 participants