File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3175,24 +3175,31 @@ from typing import TypeVar
31753175class A: ...
31763176class 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
31873187def 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
31943194T_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+
31963203def f2(self, obj: T_value) -> T_value:
31973204 if type(obj) == A:
31983205 return A()
You can’t perform that action at this time.
0 commit comments