Skip to content

Incorrect subtyping with bound typevar #13220

Closed

Description

@hauntsaninja

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)

Activity

  1. Akuli commented on Oct 14, 2022

    @Akuli
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions