-
Notifications
You must be signed in to change notification settings - Fork 216
Closed
Labels
bugSomething isn't workingSomething isn't workinggenericsBugs or features relating to ty's generics implementationBugs or features relating to ty's generics implementationtype propertiessubtyping, assignability, equivalence, and moresubtyping, assignability, equivalence, and more
Milestone
Description
When we do subtype/assignability checks within a generic scope, we don't consider two different typevars to be equivalent, even if they have the same bounds/constraints, because they could specialize to two different types.
But when we compare two unspecialized generic signatures for assignability/subtyping, this consideration does not apply. Two identical signatures, except that they use a different typevar (with the same bounds/constraints), are the same signature; typevar identity is irrelevant. In this example, all six assertions should pass; currently only the first and third and fifth pass:
from typing import TypeVar, Callable
from ty_extensions import is_assignable_to, is_subtype_of, static_assert
T = TypeVar("T")
U = TypeVar("U")
static_assert(is_assignable_to(Callable[[T], T], Callable[[T], T]))
static_assert(is_assignable_to(Callable[[T], T], Callable[[U], U]))
static_assert(is_subtype_of(Callable[[T], T], Callable[[T], T]))
static_assert(is_subtype_of(Callable[[T], T], Callable[[U], U]))
static_assert(is_equivalent_to(Callable[[T], T], Callable[[T], T]))
static_assert(is_equivalent_to(Callable[[T], T], Callable[[U], U]))Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggenericsBugs or features relating to ty's generics implementationBugs or features relating to ty's generics implementationtype propertiessubtyping, assignability, equivalence, and moresubtyping, assignability, equivalence, and more