pylint icon indicating copy to clipboard operation
pylint copied to clipboard

No type narrowing takes place in `or` statements following negated `isinstance`

Open socketpair opened this issue 2 years ago • 1 comments

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

socketpair avatar Aug 27 '21 08:08 socketpair

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

socketpair avatar Mar 21 '24 16:03 socketpair