Closed
Description
Mypy believes that it is impossible for an isinstance
to succeed if the known type has a generic and the subtype has specified that generic.
To Reproduce
from typing import Generic, TypeVar, cast
T = TypeVar("T")
class A(Generic[T]):
pass
class B(A[str]):
something: int = 0
def f(b: A[T]) -> None:
if isinstance(b, B):
print(b.something)
Expected Behavior
Mypy should have no problems with this code
Actual Behavior
dumb_test.py:16: error: <nothing> has no attribute "something" [attr-defined]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.4.1. This bug reproduces at least back to 1.2.0
- Mypy command-line flags: None. Just run with
mypy FILE
- Mypy configuration options from
mypy.ini
(and other config files): - Python version used: 3.10.0