Skip to content

Commit 689c119

Browse files
committed
Add dedicated tests for key resolved issues
1 parent fac2854 commit 689c119

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

test-data/unit/check-generics.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,3 +3563,18 @@ def foo(x: T):
35633563
reveal_type(C) # N: Revealed type is "Overload(def [T, S] (x: builtins.int, y: S`-1) -> __main__.C[__main__.Int[S`-1]], def [T, S] (x: builtins.str, y: S`-1) -> __main__.C[__main__.Str[S`-1]])"
35643564
reveal_type(C(0, x)) # N: Revealed type is "__main__.C[__main__.Int[T`-1]]"
35653565
reveal_type(C("yes", x)) # N: Revealed type is "__main__.C[__main__.Str[T`-1]]"
3566+
3567+
[case testInstanceMethodBoundOnClass]
3568+
from typing import TypeVar, Generic
3569+
3570+
T = TypeVar("T")
3571+
class B(Generic[T]):
3572+
def foo(self) -> T: ...
3573+
class C(B[T]): ...
3574+
class D(C[int]): ...
3575+
3576+
reveal_type(B.foo) # N: Revealed type is "def [T] (self: __main__.B[T`1]) -> T`1"
3577+
reveal_type(B[int].foo) # N: Revealed type is "def (self: __main__.B[builtins.int]) -> builtins.int"
3578+
reveal_type(C.foo) # N: Revealed type is "def [T] (self: __main__.B[T`1]) -> T`1"
3579+
reveal_type(C[int].foo) # N: Revealed type is "def (self: __main__.B[builtins.int]) -> builtins.int"
3580+
reveal_type(D.foo) # N: Revealed type is "def (self: __main__.B[builtins.int]) -> builtins.int"

test-data/unit/check-protocols.test

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4460,3 +4460,48 @@ f2(a4) # E: Argument 1 to "f2" has incompatible type "A4"; expected "P2" \
44604460
# N: foo: expected "B1", got "str" \
44614461
# N: foo: expected setter type "C1", got "str"
44624462
[builtins fixtures/property.pyi]
4463+
4464+
[case testProtocolImplementationWithDescriptors]
4465+
from typing import Any, Protocol
4466+
4467+
class Descr:
4468+
def __get__(self, inst: Any, owner: Any) -> int: ...
4469+
4470+
class DescrBad:
4471+
def __get__(self, inst: Any, owner: Any) -> str: ...
4472+
4473+
class Proto(Protocol):
4474+
x: int
4475+
4476+
class C:
4477+
x = Descr()
4478+
4479+
class CBad:
4480+
x = DescrBad()
4481+
4482+
a: Proto = C()
4483+
b: Proto = CBad() # E: Incompatible types in assignment (expression has type "CBad", variable has type "Proto") \
4484+
# N: Following member(s) of "CBad" have conflicts: \
4485+
# N: x: expected "int", got "str"
4486+
4487+
[case testProtocolCheckDefersNode]
4488+
from typing import Any, Callable, Protocol
4489+
4490+
class Proto(Protocol):
4491+
def f(self) -> int:
4492+
...
4493+
4494+
def defer(f: Callable[[Any], int]) -> Callable[[Any], str]:
4495+
...
4496+
4497+
def bad() -> Proto:
4498+
return Impl() # E: Incompatible return value type (got "Impl", expected "Proto") \
4499+
# N: Following member(s) of "Impl" have conflicts: \
4500+
# N: Expected: \
4501+
# N: def f(self) -> int \
4502+
# N: Got: \
4503+
# N: def f() -> str \
4504+
4505+
class Impl:
4506+
@defer
4507+
def f(self) -> int: ...

0 commit comments

Comments
 (0)