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 for function call in dictionary #5113

Closed
hbraha opened this issue Oct 4, 2021 · 5 comments
Closed

False positive not callable for function call in dictionary #5113

hbraha opened this issue Oct 4, 2021 · 5 comments
Assignees
Labels
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

@hbraha
Copy link

hbraha commented Oct 4, 2021

Bug description

ATTRIBUTES = {
        'DOMAIN': ("domain", str),
        'IMAGE': ("image", str),
}

for key, (name, validate) in ATTRIBUTES.items():
    name = validate(1)

Configuration

No response

Command used

pylint test1.py

Pylint output

************* Module test1
test1.py:8:11: E1102: validate is not callable (not-callable)

Expected behavior

no error.

Pylint version

pylint 2.10.0
astroid 2.7.3
Python 3.6.8 (default, Mar 18 2021, 08:58:41)

OS / Environment

Red Hat Enterprise Linux release 8.4

Additional dependencies

No response

@hbraha hbraha added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 4, 2021
gerrit-ovirt-org pushed a commit to oVirt/vdsm that referenced this issue Oct 5, 2021
It appears that internal pylint errors [1] such as:
"internal error with sending report for module
['lib/vdsm/storage/lvm.py'] 'Name' object has no attribute 'value'"

prevents Pylint from working properly and reports errors in some
modules. pylint bug reported for the issue[2].
bumping up pylint version seems to overcome this error.

Several true positives errors reported in the new pylint version,
such as:
"lib/vdsm/storage/lvm.py:1409:14: E1120: No value for argument 'rc' in
constructor call (no-value-for-parameter) "

Additionally, false negatives errors are also reported:
"lib/vdsm/storage/volumemetadata.py:101:29: E1102: validate is not
callable (not-callable)"

in order to pass the build and upgrade the pylint version,
the errors have been skipped. the true positive errors will
 be handle in the next patch.

[1] https://jenkins.ovirt.org/blue/organizations/jenkins/
vdsm_standard-check-patch/detail/vdsm_standard-check-patch/29942/
pipeline/151#step-264-log-1372

[2] pylint-dev/pylint#5113

Signed-off-by: hbraha <[email protected]>
Signed-off-by: Marcin Sobczyk <[email protected]>
Change-Id: Idae409022d60ace91a27fc10a7130609502ed0b8
@mbyrnepr2
Copy link
Member

It seems that when astroid visits the tuple node key, (name, validate), the newnode which is produced has elts which contain only name and validate elements (and the key is missing).

Possibly this is due to recursion on this line where the visit method recurses into the visit_tuple method again and overwrites the newnode.elts which at this point contains the key object:
https://github.com/PyCQA/astroid/blob/main/astroid/rebuilder.py#L2208

elts assigned here: https://github.com/PyCQA/astroid/blob/main/astroid/nodes/node_classes.py#L335

@Pierre-Sassoulas do you think this sounds like the right track?

Aside from this the reported sample code works ok if it is simplified to:

ATTRIBUTES = {
        'DOMAIN': str,
        'IMAGE':  str,
}

for key, validate in ATTRIBUTES.items():
    name = validate(1)

In general, pylint doesn't report any issues with the following:

for i, j, k, l, m, n, o, p in {"a": "b"}.items():
    print(i, j, k, l, m, n, o, p)

@DanielNoord
Copy link
Collaborator

@mbyrnepr2 That certainly seems like an issue! Good job on identifying it!

@Pierre-Sassoulas Pierre-Sassoulas added 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 Dec 18, 2021
@Pierre-Sassoulas
Copy link
Member

the visit method recurses into the visit_tuple method again and overwrites the newnode.elts

This sounds problematic indeed, good job finding this !

@mbyrnepr2
Copy link
Member

@Pierre-Sassoulas @DanielNoord thanks for looking.
I take back what I said about the recursion being an issue in my previous comment. On further examination that logic looks ok - I must have confused myself when debugging.

The following changes seem to fix it, but I'll leave as draft for now as I would like to share progress but also double-check when I have more time:
https://github.com/PyCQA/pylint/pull/5593/files
https://github.com/PyCQA/astroid/pull/1311/files

mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue Jan 27, 2022
mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue Feb 11, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Bug 🪲 labels Jul 5, 2022
@mbyrnepr2 mbyrnepr2 self-assigned this Sep 16, 2022
@mbyrnepr2
Copy link
Member

I think we can close once #5593 is merged (functional test).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

4 participants