Skip to content

type alias with typevar + --disallow-any-generic => unexpected error? #5462

@asottile

Description

@asottile

This is a simplified example from a larger project. I've resorted to spamming Any and avoiding the TypeVars for now since type is longer than the code itself 😆

import contextlib
from typing import Callable
from typing import Generator
from typing import Iterable
from typing import TypeVar


T = TypeVar('T')
T2 = TypeVar('T2')
MC = Callable[[Callable[[T2], T], Iterable[T2]], Iterable[T]]


@contextlib.contextmanager
def f() -> Generator[Callable[[Callable[[T2], T], Iterable[T2]], Iterable[T]], None, None]:
    yield map


@contextlib.contextmanager
def f2() -> Generator[MC, None, None]:
    yield map

I expect f and f2 to be identical, however:

$ mypy t.py --disallow-any-generic
t.py:19: error: Missing type parameters for generic type

I can silence the error by doing:

@contextlib.contextmanager
def f2() -> Generator[MC[T2, T], None, None]:
    yield map

or

@contextlib.contextmanager
def f2() -> Generator[MC[T, T2], None, None]:
    yield map

but it's unclear to me what that's doing and/or why it is different

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions