-
Notifications
You must be signed in to change notification settings - Fork 273
Open
Labels
bugSomething isn't workingSomething isn't workinggenericsBugs or features relating to ty's generics implementationBugs or features relating to ty's generics implementationoverloads
Milestone
Description
Summary
Observe: the first reveal_type shows us solving the type variables correctly, but for the second reveal_type, not only do we fail to solve the type variables, we fallback to Unknown for the whole type!
from typing import Any, overload, reveal_type
class Invariant[KT, VT]:
attr2: VT
@overload
def foo(self, other: Invariant[KT, VT]) -> Invariant[KT, VT]: ...
@overload
def foo[T1, T2](self, other: Invariant[T1, T2]) -> Invariant[KT | T1, VT | T2]: ...
def foo(self, other):
raise NotImplementedError
def g(x: Invariant[int, int], y: Invariant[int, str], z: Invariant[int, Any]):
reveal_type(x.foo(y)) # Invariant[int, int | str]
reveal_type(x.foo(z)) # ty: Unknown
# pycroscope: Any[multiple_overload_matches]
# mypy, zuban: Invariant[Any, Any]
# pyrefly, pyright: Invariant[int, int]This comes up in the real world with dict.__or__ in typeshed:
Meaning:
reveal_type({"foo": "bar"} | {}) # UnknownMultiplay gist comparing our inference with other type checkers: 0685f09832604c2cb53928d004881454.
Version
No response
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 implementationoverloads