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

Incorrect number of arguments reported when function is imported over #3675

Closed
MarkCBell opened this issue Jun 9, 2020 · 3 comments · Fixed by #5409
Closed

Incorrect number of arguments reported when function is imported over #3675

MarkCBell opened this issue Jun 9, 2020 · 3 comments · Fixed by #5409
Labels
Bug 🪲 Good first issue Friendly and approachable by new contributors Hacktoberfest Help wanted 🙏 Outside help would be appreciated, good for new contributors Regression
Milestone

Comments

@MarkCBell
Copy link
Contributor

MarkCBell commented Jun 9, 2020

Steps to reproduce

  1. Create other_file.py containing:
def f(x, y):
    return x + y
  1. Run pylint on:
"""pylint test module"""
    
def f(x):
    return x + 1

def test_one(param):
    """function defined above is matched first"""
    tmp = f
    if param == 0:
        from other_file import f as tmp  # pylint: disable=import-outside-toplevel
        return tmp(1, 4)  # <-- E1121: Too many positional arguments for function call (too-many-function-args)
    return tmp(1)

print(test_one(0))  # Prints "5"
print(test_one(1))  # Prints "2"

Current behavior

Pylint reports that line 12 was passed "too many positional arguments for function call (too-many-function-args)"

Expected behavior

Pylint should not report an issue since within this if statement tmp refers to the imported function which can be called with two arguments.

pylint --version output

pylint 2.5.2
astroid 2.4.1
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0]

@MarkCBell MarkCBell changed the title Pylint Pylint reports incorrect number of arguments to networkx.shortest_path Jun 9, 2020
@MarkCBell MarkCBell changed the title Pylint reports incorrect number of arguments to networkx.shortest_path Incorrect number of arguments to networkx.shortest_path reported Jun 9, 2020
@MarkCBell MarkCBell changed the title Incorrect number of arguments to networkx.shortest_path reported Incorrect number of arguments reported when function is imported over Jun 10, 2020
@MarkCBell
Copy link
Contributor Author

The issues appears to be caused by changes introduced in commit 01dfa52 to safe_infer in pylint/checkers/utils.py to address #2503. This appears to be because the safe_infer only checks the types of the nodes are the same. In this case they are both functions which is good enough to pass this test but they are functions which take different numbers of arguments and so there is ambiguity about which one to use.

@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue and for the analysis.

@Pierre-Sassoulas Pierre-Sassoulas added the Help wanted 🙏 Outside help would be appreciated, good for new contributors label Feb 20, 2021
@MarkCBell
Copy link
Contributor Author

Thank you. As the original title might suggest, I encountered this by running pylint on the following code:

import networkx as nx

G = nx.Graph([(1, 2), (2, 3), (2, 4)])
path = nx.algorithms.shortest_path(G, 1, 4)  # <-- Triggers E1121: Too many positional arguments for function call
print(path)

This is because networkx uses this trick to import shortest_path over an existing function.

@Pierre-Sassoulas Pierre-Sassoulas added the Good first issue Friendly and approachable by new contributors label Mar 2, 2021
aafshinfard added a commit to bcgsc/physlr that referenced this issue Apr 1, 2021
temporarily disabling pylint as it has an active bug for two lines: pylint-dev/pylint#3675
aafshinfard added a commit to bcgsc/physlr that referenced this issue Apr 1, 2021
* happy pylint (newly added linter)

Now to iterate over a `dict`, the only acceptable way is two call `.items()`

* disable pylint for two lines due to bugs

temporarily disabling pylint as it has an active bug for two lines: pylint-dev/pylint#3675

* fix typo

* happy pylint warnings

* Happy pylint recoms

* fix typo
@Pierre-Sassoulas Pierre-Sassoulas pinned this issue May 14, 2021
@Pierre-Sassoulas Pierre-Sassoulas unpinned this issue May 21, 2021
jacobtylerwalls added a commit to jacobtylerwalls/pylint that referenced this issue Nov 27, 2021
jacobtylerwalls added a commit to jacobtylerwalls/pylint that referenced this issue Nov 27, 2021
jacobtylerwalls added a commit to jacobtylerwalls/pylint that referenced this issue Nov 27, 2021
jacobtylerwalls added a commit to jacobtylerwalls/pylint that referenced this issue Dec 4, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.0 milestone Dec 5, 2021
Pierre-Sassoulas pushed a commit that referenced this issue Dec 14, 2021
…when number of arguments differ (#5409)

Co-authored-by: Daniël van Noord <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Good first issue Friendly and approachable by new contributors Hacktoberfest Help wanted 🙏 Outside help would be appreciated, good for new contributors Regression
Projects
None yet
2 participants