pylint
pylint copied to clipboard
No type narrowing takes place in `or` statements following negated `isinstance`
Bug description
session: aiohttp.ClientSession
try:
async with session.get('...') as resp:
await resp.text()
except Exception as exc:
if not isinstance(exc, aiohttp.ClientResponseError) or exc.status != 404:
xxx()
else:
yyy()
Configuration
No response
Command used
pylint a.py
Pylint output
E1101: Instance of 'Exception' has no 'status' member (no-member)
Expected behavior
no error here
Pylint version
pylint 2.9.6
astroid 2.6.6
Python 3.9.6 (default, Jul 16 2021, 00:00:00)
[GCC 11.1.1 20210531 (Red Hat 11.1.1-3)]
OS / Environment
Fedora 34
Additional dependencies
No response
pylint 3.0.4
astroid 3.0.3
Python 3.12.2 (main, Feb 21 2024, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)]
Still actual
It appears this affects and without not, as well as or not:
import random
class Foo:
__slots__ = ()
class Bar(Foo):
__slots__ = ("x",)
x: int
def __init__(self, x: int) -> None:
self.x = x
def make_foo() -> Foo:
return Foo()
def main() -> None:
obj = make_foo()
if isinstance(obj, Bar) and obj.x > 1: # E1101: Instance of 'Foo' has no 'x' member (no-member)
print(obj.x) # E1101: Instance of 'Foo' has no 'x' member (no-member)
main()