Skip to content

Commit f7b7cb8

Browse files
committed
Add a test and a comment
1 parent cb262e1 commit f7b7cb8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

mypy/checkmember.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,9 @@ def f(self: S) -> T: ...
10641064
if isinstance(selfarg, Instance) and isinstance(p_dispatched_arg_type, Instance):
10651065
if selfarg.type is p_dispatched_arg_type.type and selfarg.args:
10661066
if not is_overlapping_types(p_dispatched_arg_type, selfarg):
1067+
# This special casing is needed since `actual <: erased(template)`
1068+
# logic below doesn't always work, and a more correct approach may
1069+
# be tricky.
10671070
continue
10681071
# This matches similar special-casing in bind_self(), see more details there.
10691072
self_callable = name == "__call__" and isinstance(selfarg, CallableType)

test-data/unit/check-selftype.test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,3 +2282,30 @@ class Check:
22822282
reveal_type(Check.foo()) # N: Revealed type is "def () -> __main__.Check"
22832283
reveal_type(Check().foo()) # N: Revealed type is "__main__.Check"
22842284
[builtins fixtures/tuple.pyi]
2285+
2286+
[case testSelfTypeUpperBoundFiler]
2287+
from typing import Generic, TypeVar, overload, Sequence
2288+
2289+
class B: ...
2290+
class C(B): ...
2291+
2292+
TB = TypeVar("TB", bound=B)
2293+
TC = TypeVar("TC", bound=C)
2294+
2295+
class G(Generic[TB]):
2296+
@overload
2297+
def test(self: G[TC]) -> list[TC]: ...
2298+
@overload
2299+
def test(self: G[TB]) -> Sequence[TB]: ...
2300+
def test(self):
2301+
...
2302+
2303+
class D1(B): ...
2304+
class D2(C): ...
2305+
2306+
gb: G[D1]
2307+
gc: G[D2]
2308+
2309+
reveal_type(gb.test()) # N: Revealed type is "typing.Sequence[__main__.D1]"
2310+
reveal_type(gc.test()) # N: Revealed type is "builtins.list[__main__.D2]"
2311+
[builtins fixtures/list.pyi]

0 commit comments

Comments
 (0)