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
Given the following code (mypy 0.590 and python 3.6.5):
from typing import *
class A(object):
def method(self) -> str:
return ''
R = TypeVar('R')
class B(object):
def func(self, instance: A, instance_type: Type[R]) -> None:
reveal_type(instance)
if isinstance(instance, instance_type):
reveal_type(instance)
instance.method()
I get the following response:
test.py:11: error: Revealed type is 'test.A'
test.py:13: error: Revealed type is 'builtins.None'
test.py:14: error: "None" has no attribute "method"
I would have expected the type of instance to have at the very least been a subclass of A, given that it was before it went into the call. So something like:
test.py:11: error: Revealed type is 'test.A'
test.py:13: error: Revealed type is 'R'
Or perhaps more complex to indicate it subclasses from both A and R, (but I don't know the syntax for that). It makes no difference whether R is bound to A or not.
The text was updated successfully, but these errors were encountered:
The return type was removed in the simplification (since it wasn't required to produce the issue). The original return type was List[Tuple[str, str, R]], but that gave rise to #4949 so I figured I'd leave it out in this example.
Also, in this instance, it isn't strictly multiple inheritance, since this happens even when R is bound to A. Having said that, according to the bug you mentioned Type[R] might be classed as a really weird situation and so it may well be the same bug. This seems to be specific to TypeVar because the following code returns as expected, which should be equivalent to the TypeVar('R', bound = A) situation:
from typing import *
class A(object):
def method(self) -> str:
return ''
class AA(A):
pass
class B(object):
def func(self, instance: AA, instance_type: Type[A]) -> None:
reveal_type(instance)
if isinstance(instance, instance_type):
reveal_type(instance)
instance.method()
Given the following code (mypy 0.590 and python 3.6.5):
I get the following response:
I would have expected the type of instance to have at the very least been a subclass of A, given that it was before it went into the call. So something like:
Or perhaps more complex to indicate it subclasses from both A and R, (but I don't know the syntax for that). It makes no difference whether R is bound to A or not.
The text was updated successfully, but these errors were encountered: