Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No type narrowing takes place in or statements following negated isinstance #4920

Open
socketpair opened this issue Aug 27, 2021 · 2 comments
Labels
Control flow Requires control flow understanding False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@socketpair
Copy link

socketpair commented Aug 27, 2021

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 socketpair added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 27, 2021
@Pierre-Sassoulas Pierre-Sassoulas added Control flow Requires control flow understanding and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 3, 2021
@jacobtylerwalls jacobtylerwalls changed the title Values tracking does not work No type narrowing takes place in or statements following negated isinstance Mar 31, 2022
@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Bug 🪲 labels Jul 13, 2022
@socketpair
Copy link
Author

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

@Hawk777
Copy link

Hawk777 commented Jul 25, 2024

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Control flow Requires control flow understanding False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

3 participants