Closed
Description
This came up when I merged python/typeshed#223.
I think I have a complete repo that doesn't depend on the stubs. Consider this:
from typing import TypeVar, Generic, Tuple, overload
KT = TypeVar('KT')
VT = TypeVar('VT')
class A(Generic[KT, VT]):
def get(self, arg: KT) -> VT:
pass
a = A() # type: A[Tuple[int, int], int]
a.get((0, 0)) # OK
class B(Generic[KT, VT]):
@overload
def get(self, arg: KT) -> VT:
pass
@overload
def get(self, arg: KT, default: VT) -> VT:
pass
b1 = B() # type: B[int, int]
b1.get(0) # OK
b2 = B() # type: B[Tuple[int, int], int]
b2.get((0, 0)) # error here
I get an error on the very last line (b2.get((0, 0)
):
x.py:24: error: No overload variant of "get" of "B" matches argument types [Tuple[builtins.int, builtins.int]]
But there's no error two lines above, on b1.get(0)
. Also note that the same code with class A which does not overload get()
) has no errors. I've got a feeling that there's a subtle bug in the handling of type variables that only shows up when a Tuple is matched against an overloaded method.
Metadata
Metadata
Assignees
Labels
No labels