pylint icon indicating copy to clipboard operation
pylint copied to clipboard

[too-many-function-args] False negative when calling `super().__init__()` with non-self argument

Open da-dada opened this issue 1 year ago • 2 comments

Bug

no error given in pylint, no run in Python

class WinHlp:

    def print_text(self, txt):
        print(f'{__class__} {txt=}')

class Window:

    def print_text(self, txt):
        print(f'{__class__} {txt=}')

class Win(WinHlp, Window):
    def __init__(self, txt):
        super().__init__(txt)

        self.print_text(txt)

Win('hello')

Configuration

No response

Command used

pylint a.py

Pylint output

Microsoft Windows [Version 10.0.19045.4170]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Me>cd C:\Users\Me\Documents\Programming\Python\Mylib\experimental\subclassing\more than 1 base\discussions

C:\Users\Me\Documents\Programming\Python\Mylib\experimental\subclassing\more than 1 base\discussions>pylint test.py
************* Module test
test.py:1:0: C0114: Missing module docstring (missing-module-docstring)
test.py:1:0: C0115: Missing class docstring (missing-class-docstring)
test.py:3:4: C0116: Missing function or method docstring (missing-function-docstring)
test.py:1:0: R0903: Too few public methods (1/2) (too-few-public-methods)
test.py:6:0: C0115: Missing class docstring (missing-class-docstring)
test.py:8:4: C0116: Missing function or method docstring (missing-function-docstring)
test.py:6:0: R0903: Too few public methods (1/2) (too-few-public-methods)
test.py:11:0: C0115: Missing class docstring (missing-class-docstring)
test.py:11:0: R0903: Too few public methods (1/2) (too-few-public-methods)

------------------------------------------------------------------
Your code has been rated at 1.82/10 (previous run: 8.82/10, -7.00)


C:\Users\Me\Documents\Programming\Python\Mylib\experimental\subclassing\more than 1 base\discussions>

Expected behavior

Microsoft Windows [Version 10.0.19045.4170] (c) Microsoft Corporation. All rights reserved.

C:\Users\Me>cd C:\Users\Me\Documents\Programming\Python\Mylib\experimental\subclassing\more than 1 base\discussions

C:\Users\Me\Documents\Programming\Python\Mylib\experimental\subclassing\more than 1 base\discussions>test.py Traceback (most recent call last): File "C:\Users\Me\Documents\Programming\Python\Mylib\experimental\subclassing\more than 1 base\discussions\test.py", l ine 17, in Win('hello') File "C:\Users\Me\Documents\Programming\Python\Mylib\experimental\subclassing\more than 1 base\discussions\test.py", l ine 13, in init super().init(txt) TypeError: object.init() takes exactly one argument (the instance to initialize)

C:\Users\Me\Documents\Programming\Python\Mylib\experimental\subclassing\more than 1 base\discussions>

Pylint version

pylint 3.1.0
astroid 3.1.0
Python 3.12.2

OS / Environment

Windows 10

Additional dependencies

No response

da-dada avatar Mar 24 '24 17:03 da-dada

Thanks for the report!

Slimmer reproducer without multiple bases:

class Window:
    ...

class Win(Window):
    def __init__(self, txt):
        super().__init__(txt)

Win('hello')

I'm assuming that this case is missed in this block of code:

https://github.com/pylint-dev/pylint/blob/178491e295a0721681a526a622e01b4c01c56b08/pylint/checkers/typecheck.py#L1508-L1518

jacobtylerwalls avatar Mar 24 '24 18:03 jacobtylerwalls

I am looking to solve this one but I am not able to get how to add this condition to the above mentioned code block?

shekhuverma avatar Apr 16 '24 14:04 shekhuverma