You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know if I've described this accurately, but it's probably best described by some code. I've reduced this to the simple scenario I can find:
T = TypeVar('T', bound = A)
def check_subtype(instance: A, instance_type: Tuple[Type[T], ...]) -> Optional[T]:
if isinstance(instance, instance_type):
return instance
return None
returns
test.py:15: error: Incompatible return value type (got "A", expected "Optional[T]")
Removing the Tuple and only allowing one Type to be passed to isinstance gives no errors:
T = TypeVar('T', bound = A)
def check_subtype(instance: A, instance_type: Type[T]) -> Optional[T]:
if isinstance(instance, instance_type):
return instance
return None
My understanding was that the signature for isinstance was Union[Type[T], Tuple[Type[T], ...]], so I'd have expected similar outputs when providing it a Type[T] versus a Tuple[Type[T], ...]?
The text was updated successfully, but these errors were encountered:
@roosemberth I don't think that code is correct, because you use TypeVars without anything to constrain them. Usually you only want to use TypeVars in the signature of a function if you're using them in multiple places, because the point of a TypeVar is to constrain multiple types to be the same.
Maybe there's still a bug here (mypy's error message could be better), but in that case it's unrelated to the original bug in this issue, which is about isinstance.
Mypy version: 0.590
Python version: 3.6.5
I don't know if I've described this accurately, but it's probably best described by some code. I've reduced this to the simple scenario I can find:
returns
Removing the Tuple and only allowing one Type to be passed to isinstance gives no errors:
My understanding was that the signature for
isinstance
wasUnion[Type[T], Tuple[Type[T], ...]]
, so I'd have expected similar outputs when providing it aType[T]
versus aTuple[Type[T], ...]
?The text was updated successfully, but these errors were encountered: