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

False positive "not-callable" after is not None #6005

Closed
jab opened this issue Mar 27, 2022 · 2 comments
Closed

False positive "not-callable" after is not None #6005

jab opened this issue Mar 27, 2022 · 2 comments
Labels
Control flow Requires control flow understanding Duplicate 🐫 Duplicate of an already existing issue 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

@jab
Copy link
Contributor

jab commented Mar 27, 2022

Bug description

Minimized reproducer:

# pylint: disable=too-few-public-methods

"Module to repro false positive 'not-callable' error."""

import weakref


class Repro:
    """Class to repro false positive bug."""

    def __init__(self):
        self._weak = None

    def repro(self):
        """Method to repro false positive bug."""
        weak = getattr(self, '_weak', None)
        if weak is not None:
            strong = weak()  # false positive error here
            if strong is not None:
                return strong
        self._weak = weakref.ref(self)
        return self._weak()

See the following line for a real-world example where this false positive is occurring: https://github.com/jab/bidict/blob/caf703e959ed4471bc391a7794411864c1d6ab9d/bidict/_base.py#L185

Configuration

No response

Command used

pylint repro.py

Pylint output

************* Module repro
repro.py:18:21: E1102: weak is not callable (not-callable)

Expected behavior

No error should be flagged here.

Pylint version

pylint 2.13.2
astroid 2.11.2
Python 3.10.2 (main, Feb  2 2022, 07:36:01) [Clang 12.0.0 (clang-1200.0.32.29)]

OS / Environment

No response

Additional dependencies

No response

@jab jab added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Mar 27, 2022
@jacobtylerwalls
Copy link
Member

It's possible this is addressed by pylint-dev/astroid#1189

@jacobtylerwalls jacobtylerwalls added Control flow Requires control flow understanding False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Mar 27, 2022
@jacobtylerwalls jacobtylerwalls changed the title false positive "not-callable" error false positive "not-callable" after is not None Mar 27, 2022
@Pierre-Sassoulas Pierre-Sassoulas changed the title false positive "not-callable" after is not None False positive "not-callable" after is not None Jul 13, 2022
@Pierre-Sassoulas Pierre-Sassoulas added the Needs PR This issue is accepted, sufficiently specified and now needs an implementation label Jul 13, 2022
@Pierre-Sassoulas
Copy link
Member

Closing in favor of #7412, more generic and detailed.

@Pierre-Sassoulas Pierre-Sassoulas closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2024
@Pierre-Sassoulas Pierre-Sassoulas added the Duplicate 🐫 Duplicate of an already existing issue label May 4, 2024
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 Duplicate 🐫 Duplicate of an already existing issue 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