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

not-callable: false positive due to conflit between "next" user-function and "collections.abc" #3970

Closed
bansan85 opened this issue Dec 7, 2020 · 2 comments · Fixed by #4348
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@bansan85
Copy link

bansan85 commented Dec 7, 2020

Steps to reproduce

from collections.abc import Callable


class Class:
    def next(self):
        pass

    def __init__(self):
        self.next()

Current behavior

self.next is not callable

These is no warning if I remove the line from collections.abc import Callable

Expected behavior

No warning message.

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]
@bansan85 bansan85 changed the title not-callable: false positive due to conflit between next user-function not-callable: false positive due to conflit between "next" user-function and "collections.abc" Dec 7, 2020
@hippo91
Copy link
Contributor

hippo91 commented Dec 8, 2020

@bansan85 thanks for your report. I can reproduce it with the following snippet:

#pylint: disable=missing-module-docstring, missing-function-docstring
#pylint: disable=missing-class-docstring, too-few-public-methods
from collections.abc import Callable


class Class(Callable):
    def __call__(self, *args, **kwargs):
        pass

    def next(self):
        pass

    def __init__(self):
        self.next()

@hippo91 hippo91 added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code labels Dec 8, 2020
@exquo
Copy link

exquo commented Mar 9, 2021

Looks like this affects the whole collections package, rather than just the Callable class or the collections.abc module.
Replacing import line with

import collections

reports the same pylint error.

I believe this is a manifestation of #4221 caused by these lines in __init__.py: (1), (2).

The current issue is probably the cause of #3595 and various comments in it. All it takes to get the error is import collections (or import something that in turn imports collections), and call <anything>.next() or <anything>.prev().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants