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

Incorrect subtyping with bound typevar #13220

Closed
hauntsaninja opened this issue Jul 23, 2022 · 1 comment · Fixed by #16184
Closed

Incorrect subtyping with bound typevar #13220

hauntsaninja opened this issue Jul 23, 2022 · 1 comment · Fixed by #16184
Labels
affects-typeshed Anything that blocks a typeshed change bug mypy got something wrong topic-type-variables

Comments

@hauntsaninja
Copy link
Collaborator

From python/typeshed#8372

from typing import Callable, TypeVar, Any, Mapping, Optional
T = TypeVar("T", bound=Mapping[str, Any])
def raises(opts: Optional[T]) -> T: pass
def assertRaises(cb: Callable[..., object]) -> None: pass
assertRaises(raises)
@Akuli
Copy link
Contributor

Akuli commented Oct 14, 2022

Slightly simpler reproducer:

from typing import Callable, TypeVar
T = TypeVar("T", bound=list[int])
def raises(opts: T | None) -> T: pass
x: Callable[..., object] = raises

Expected result: no error because Callable[..., object] should accept any callable, even with TypeVars in it.

Actual result: assignment on last line fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-typeshed Anything that blocks a typeshed change bug mypy got something wrong topic-type-variables
Projects
None yet
3 participants