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 E1102 when adding a non-callable attribute to object #4221

Closed
exquo opened this issue Mar 9, 2021 · 0 comments · Fixed by #4348
Closed

False positive E1102 when adding a non-callable attribute to object #4221

exquo opened this issue Mar 9, 2021 · 0 comments · Fixed by #4348

Comments

@exquo
Copy link

exquo commented Mar 9, 2021

Steps to reproduce

'test'.startswith('t')
o = object()
x = 42
if o is x:
    o.startswith = None

Current behavior

$ pylint -E file.py
************* Module file
file.py:1:0: E1102: 'test'.startswith is not callable (not-callable)

Expected behavior

No errors.

pylint --version output

pylint 2.7.2
astroid 2.5.1
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0]

Pylint probably reasons like this: str is a subclass of object; object's attribute is assigned to non-callable; thus, str's attribute by the same name should be non-callable. I can see the logic here, but the error is reported on the very first line, before the attribute has the chance to get re-assigned.

By itself, the above example code is not very meaningful. I'm reporting it because this seems to be the underlying cause of #3970 (comment). Also, it might manifest itself in other, more practical scenarios than the example above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant