Bug Report
Type narrowing using isinstance with 1.7 behaves differently from 1.6 for seemingly valid code.
To Reproduce
import typing
class A:
def write(self) -> str:
return "A"
# succeeds
def eq1(self, other: typing.Any) -> bool:
if other:
if isinstance(other, self.__class__):
return self.write() == other.write()
return False
# fails
def eq2(self, other: typing.Any) -> bool:
if other and isinstance(other, self.__class__):
return self.write() == other.write()
return False
Expected Behavior
The eq1 and eq2 should both be valid code. eq2 fails under 1.7 but succeeded under 1.6.
Actual Behavior
file.py:15: error: Returning Any from function declared to return "bool" [no-any-return]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.7.0
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini (and other config files):
# Global options:
[mypy]
ignore_missing_imports = True
follow_imports = silent
strict = True
Python 3.12 macos-arm64
Bug Report
Type narrowing using
isinstancewith 1.7 behaves differently from 1.6 for seemingly valid code.To Reproduce
Expected Behavior
The
eq1andeq2should both be valid code.eq2fails under 1.7 but succeeded under 1.6.Actual Behavior
Your Environment
mypy.ini(and other config files):Python 3.12 macos-arm64