pep8-naming icon indicating copy to clipboard operation
pep8-naming copied to clipboard

False positive for N805 in a child class

Open skirpichev opened this issue 2 years ago • 3 comments

$ cat -n a.py
     1  # pylint: disable=missing-class-docstring, missing-module-docstring
     2  
     3  class Foo(type):
     4      pass
     5  
     6  
     7  class Bar(Foo):
     8      def __init__(cls):
     9          super().__init__()
$ flake8 --ignore=D100,D101,D107 a.py 
a.py:8:19: N805 first argument of a method should be named 'self'

PEP8: Always use cls for the first argument to class methods.

Note that pylint is correct here:

$ pylint a.py

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

skirpichev avatar Feb 05 '22 05:02 skirpichev

pylint does significantly more to analyze code that isn't strictly available to us. Presuming the exact case you've provided, we might be able to detect this, but if Foo were in another module, it wouldn't actually work. We have some notion of tracking parent classes already so we might be able to catch this but it's also rare enough that I feel people would be better served by adding # noqa: N805 to the line

sigmavirus24 avatar Feb 05 '22 15:02 sigmavirus24

Hmm, then maybe this check is not a suitable task for the pep8-naming?

skirpichev avatar Feb 05 '22 15:02 skirpichev

Hmm, then maybe this check is not a suitable task for the pep8-naming?

Checking for self? Which is right 99.99% of the time? No. It's perfectly suitable.

sigmavirus24 avatar Feb 05 '22 15:02 sigmavirus24