Skip to content

cannot apply @asynccontextmanager to a function that uses TypeVarTuple #17278

@ZeeD

Description

@ZeeD

I think this is a bug in mypy.
mypy-play.net

I want to properly annotate a generic async context manager to preserve the types of the *args in the returned value.

Ts = TypeVarTuple('Ts')

@asynccontextmanager
async def fun(*args: *Ts) -> AsyncIterator[tuple[*Ts]]:
    ...

but this snippet generate the following error

main.py:11: error: Argument 1 to "asynccontextmanager" has incompatible type "Callable[[VarArg(*Ts)], AsyncIterator[tuple[*Ts]]]"; expected "Callable[[VarArg(Never), KwArg(Never)], AsyncIterator[Never]]"  [arg-type]

The function types - without the @asynccontextmanager - seems to work correctly

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-pep-646PEP 646 (TypeVarTuple, Unpack)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions