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

[no-value-for-parameter] False negative when calling super().__init__() with non-self argument #9519

Open
da-dada opened this issue Mar 24, 2024 · 2 comments
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Good first issue Friendly and approachable by new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@da-dada
Copy link

da-dada commented Mar 24, 2024

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 da-dada added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Mar 24, 2024
@jacobtylerwalls
Copy link
Member

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:

# Decrement `num_positional_args` by 1 when a function call is assigned to a class attribute
# inside the class where the function is defined.
# This avoids emitting `too-many-function-args` since `num_positional_args`
# includes an implicit `self` argument which is not present in `called.args`.
if (
isinstance(node.frame(), nodes.ClassDef)
and isinstance(called, nodes.FunctionDef)
and called in node.frame().body
and num_positional_args > 0
and "builtins.staticmethod" not in called.decoratornames()
):

@jacobtylerwalls jacobtylerwalls added Good first issue Friendly and approachable by new contributors False Negative 🦋 No message is emitted but something is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Mar 24, 2024
@jacobtylerwalls jacobtylerwalls changed the title subclassing [no-value-for-parameter] False negative when calling super().__init__() with non-self argument Mar 24, 2024
@jacobtylerwalls jacobtylerwalls added the Needs PR This issue is accepted, sufficiently specified and now needs an implementation label Mar 24, 2024
@shekhuverma
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Good first issue Friendly and approachable by new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

3 participants