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 too-many-function-args for a function defined and called within a class #6592

Closed
nedbat opened this issue May 12, 2022 · 3 comments · Fixed by #7395
Closed

Incorrect too-many-function-args for a function defined and called within a class #6592

nedbat opened this issue May 12, 2022 · 3 comments · Fixed by #7395
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code python 3.9 Regression

Comments

@nedbat
Copy link
Contributor

nedbat commented May 12, 2022

Bug description

class Dyn:
    def _make_method(name):     # pylint: disable=no-self-argument
        def _the_method(self):
            print(name)
        return _the_method

    print_nedbat = _make_method("nedbat")

Dyn().print_nedbat()

This code works. But pylint doesn't like it:

% pylint -E weirdmethod.py
************* Module weirdmethod
weirdmethod.py:7:19: E1121: Too many positional arguments for method call (too-many-function-args)

Configuration

No response

Command used

pylint -E weirdmethod.py

Pylint output

************* Module weirdmethod
weirdmethod.py:7:19: E1121: Too many positional arguments for method call (too-many-function-args)

Expected behavior

Since the code works, this is not an error. Pylint shouldn't complain.

Pylint version

pylint 2.13.8
astroid 2.11.5
Python 3.7.13 (default, Mar 16 2022, 20:45:04)
[Clang 12.0.0 (clang-1200.0.32.29)]

(btw, this didn't happen with pylint 2.13.7 and astroid 2.11.3)

OS / Environment

Mac OS 10.15.7

Additional dependencies

No response

@nedbat nedbat added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label May 12, 2022
nedbat added a commit to nedbat/coveragepy that referenced this issue May 12, 2022
Wrote this bug for pylint, because I shouldn't have to add a pragma:
pylint-dev/pylint#6592
nedbat added a commit to nedbat/coverage-reports that referenced this issue May 12, 2022
Wrote this bug for pylint, because I shouldn't have to add a pragma:
pylint-dev/pylint#6592

https://nedbat.github.io/coverage-reports/reports/20220512_3e6ff4ff21/htmlcov
3e6ff4ff21: master
@jacobtylerwalls
Copy link
Member

jacobtylerwalls commented May 12, 2022

Thanks for the report. The behavior changed in pylint-dev/astroid#1531. I think the new result is closer to what pylint does in general, which is to complain when @staticmethod decorators are missing. When I add @staticmethod, the message goes away. I take the point, though, that the decorator is not needed at runtime!

At the very least emitting a lower severity message for this scenario is something to consider.

@nedbat
Copy link
Contributor Author

nedbat commented May 12, 2022

Huh, on 3.7-3.9, a staticmethod produces "TypeError: 'staticmethod' object is not callable". On 3.10 it works...

@jacobtylerwalls jacobtylerwalls added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Regression python 3.9 and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels May 12, 2022
@da-dada
Copy link

da-dada commented Jun 9, 2022

@nedbat, for < 3.10

class Dyn:
    @staticmethod
    def _make_method(name):
        def _the_method(self):
            print(name)
        return _the_method

print_nedbat = Dyn()._make_method("nedbat")
print_nedbat(print_nedbat)

mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue Sep 1, 2022
…l is assigned to a class attribute inside the class where the function is defined.

Closes pylint-dev#6592
mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue Sep 1, 2022
…l is assigned to a class attribute inside the class where the function is defined.

Closes pylint-dev#6592
mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue Sep 1, 2022
…l is assigned to a class attribute inside the class where the function is defined.

Closes pylint-dev#6592
mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue Sep 1, 2022
…l is assigned to a class attribute inside the class where the function is defined.

Closes pylint-dev#6592
Pierre-Sassoulas pushed a commit that referenced this issue Sep 2, 2022
…l is assigned to a class attribute inside the class where the function is defined. (#7395)

Closes #6592
Pierre-Sassoulas pushed a commit to Pierre-Sassoulas/pylint that referenced this issue Sep 6, 2022
…l is assigned to a class attribute inside the class where the function is defined. (pylint-dev#7395)

Closes pylint-dev#6592
Pierre-Sassoulas pushed a commit that referenced this issue Sep 6, 2022
…l is assigned to a class attribute inside the class where the function is defined. (#7395)

Closes #6592
webknjaz added a commit to cherrypy/cheroot that referenced this issue Sep 28, 2022
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 python 3.9 Regression
Projects
None yet
3 participants