Pylint: Unused arguments not reported in classes

Created on 4 Dec 2019  路  3Comments  路  Source: PyCQA/pylint

Steps to reproduce

Create a class as follows:

class Test:
    def __init__(self, test_arg):
        pass

and run pylint against it.

Current behavior

Pylint does not report 'unused-argument' on class methods.

Expected behavior

Pylint does report 'unused-argument' on class methods.

pylint --version output

pylint 2.4.4
astroid 2.3.3
Python 3.5.2 (default, Oct 8 2019, 13:06:37)
[GCC 5.4.0 20160609]

bug

All 3 comments

Thanks for the report!

Any news on this one? Was someone able to reproduce or is the problem with my setup somehow?

pylint writes this method off as abstract (and therefore does not emit the error message) because the body of the __init__ method is empty. If you populate the body with a single statement, the message will show.

I don't think we could make this change because it will cause to many false positives for interfaces and abstract classes.

The message works fine with:

class Test(object):
    def __init__(self, test_arg):
        a = 1

The code is very explicit:

pylint/checkers/variables.py:880

        # Don't check arguments of abstract methods or within an interface.
        is_method = node.is_method()
        if is_method and node.is_abstract():
            return

astroid/scoped_nodes.py:1626

    def is_abstract(self, pass_is_abstract=True):
        """Check if the method is abstract.

        A method is considered abstract if any of the following is true:
        * The only statement is 'raise NotImplementedError'
        * The only statement is 'pass' and pass_is_abstract is True
        * The method is annotated with abc.astractproperty/abc.abstractmethod

        :returns: True if the method is abstract, False otherwise.
        :rtype: bool
        """

I'm closing this but happy to hear objections

Was this page helpful?
0 / 5 - 0 ratings