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

False positive N805 on overriden __new__ method #3

Closed
popotam opened this issue Apr 17, 2013 · 5 comments
Closed

False positive N805 on overriden __new__ method #3

popotam opened this issue Apr 17, 2013 · 5 comments
Labels

Comments

@popotam
Copy link

popotam commented Apr 17, 2013

Description

Overriden new methods are always static methods and their first parameter should not be named self, but pep8-naming prints an error when it is not self.

How to replicate:

$ cat new_override.py 
class NewOverride(object):
    def __new__(cls):
        return object.__new__(NewOverride)
$ flake8 new_override.py 
new_override.py:2:9: N805 first argument of a method should be named 'self'
@sigmavirus24
Copy link
Member

I suspect this also happens with classmethod and staticmethod decorated methods?

@stephan-hof
Copy link
Contributor

This is a valid issuse,

So in case of __new__ the naming checker should only allow 'cls' ?
I will have a look at this on the weekend and will open a pull-request for it.

I suspect this also happens with classmethod and staticmethod decorated methods?

I don't think so, the checker tries to detect classmethod and staticmethod and does not force self there

@florentx
Copy link
Contributor

For __new__, it seems reasonable to allow only cls.

There's also __prepare__ which is a special method for metaclasses.
For this one, it seems there's no clear consensus.
http://docs.python.org/3.4/reference/datamodel.html#metaclass-example

And a quick search on Google: https://www.google.com/search?q=%22def+__prepare__%22&nfpr=1
The first argument is one of meta, metacls, cls, mcl.

@stephan-hof
Copy link
Contributor

Looking at __prepare__ it seems to me the classmethod decorator makes the first argument to appear. If you omit the classmethod decorator the signature looks like this def __prepare__(name, bases, **kwds)
Hence I would say the classmethod rule applies here too => cls

stephan-hof added a commit that referenced this issue Apr 23, 2013
@abraithwaite
Copy link

@stephan-hof Any plans for a release of the changes reflected in this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants