Skip to content

Commit b601c58

Browse files
committed
.
1 parent 2db9e30 commit b601c58

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

test-data/unit/check-narrowing.test

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,24 +3175,31 @@ from typing import TypeVar
31753175
class A: ...
31763176
class B: ...
31773177

3178-
T = TypeVar("T", A, B)
3178+
T = TypeVar("T")
31793179

3180-
def bad(self, obj: T) -> T:
3180+
def bad1(self, obj: T) -> T:
31813181
if isinstance(obj, A):
3182-
return A() # E: Incompatible return value type (got "A", expected "B")
3182+
return A() # E: Incompatible return value type (got "A", expected "T")
31833183
elif isinstance(obj, B):
3184-
return B()
3184+
return B() # E: Incompatible return value type (got "B", expected "T")
31853185
raise
31863186

31873187
def f1(self, obj: T) -> T:
31883188
if type(obj) == A:
3189-
return A()
3189+
return A() # E: Incompatible return value type (got "A", expected "T")
31903190
elif type(obj) == B:
3191-
return B()
3191+
return B() # E: Incompatible return value type (got "B", expected "T")
31923192
raise
31933193

31943194
T_value = TypeVar("T_value", A, B)
31953195

3196+
def bad2(self, obj: T_value) -> T_value:
3197+
if isinstance(obj, A):
3198+
return A() # E: Incompatible return value type (got "A", expected "B")
3199+
elif isinstance(obj, B):
3200+
return B()
3201+
raise
3202+
31963203
def f2(self, obj: T_value) -> T_value:
31973204
if type(obj) == A:
31983205
return A()

0 commit comments

Comments
 (0)