basedmypy icon indicating copy to clipboard operation
basedmypy copied to clipboard

return type on `isinstance` check with non-overlapping types is `bool` instead of `False`

Open DetachHead opened this issue 1 year ago • 0 comments

Describe the problem, ie expected/actual result (if it's not blatantly obvious)

this prevents you from being able to use cast to work around redundant-expr false positives (eg. #615)

Gist to reproduce

# mypy: enable-error-code=redundant-expr
from typing import cast

b = 1

reveal_type(isinstance(b, str)) # bool, should be False

if isinstance(b, str): # error: condition is always false
    ...
    
if cast(bool, isinstance(b, str)): # error: redundant expr
    ...

DetachHead avatar Jan 12 '24 01:01 DetachHead