Inheritance + if/elif/else chain of isinstance() doesn't constrain type as expected #4864
Labels
bug
mypy got something wrong
false-positive
mypy gave an error on correct code
priority-2-low
topic-type-narrowing
Conditional type narrowing / binder
topic-union-types
I have something like the following code:
mypy claims:
However, at line 25, it's clear that obj must be either a
B
or aC
. If I remove theelif isinstance(obj, C)
branch, then there is no error.This similar code has a related error:
Interestingly, if I remove the inheritance so that
B
andC
are no longer subclasses ofA
, there is no error.This happens on mypy 0.570 and current git (0.590-dev-3346cfad75374c096b1dd8024df24ce50f18a35c).
The text was updated successfully, but these errors were encountered: