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

Should be cls in metaclass #164

Open
Dreamsorcerer opened this issue Mar 25, 2021 · 3 comments
Open

Should be cls in metaclass #164

Dreamsorcerer opened this issue Mar 25, 2021 · 3 comments

Comments

@Dreamsorcerer
Copy link

class Aioresponses(type):
    def __new__(metacls, classname, bases, class_dict):
        ...

This produces:
./tests/unit/test_auth.py:33:18: N804 first argument of a classmethod should be named 'cls'

But, it's a metaclass, and seems to directly contradict B902 from bugbear:
./tests/unit/test_auth.py:33:17: B902 Invalid first argument 'cls' used for metaclass class method. Use the canonical first argument name in methods, i.e. metacls.

@sigmavirus24
Copy link
Member

We implement PEP 8's naming guidance. In particular https://www.python.org/dev/peps/pep-0008/#function-and-method-arguments

I'm not convinced metacls is actually canonical in this case.

@Dreamsorcerer
Copy link
Author

Hmm, it doesn't mention metaclasses at all. It looks like in cpython the most common use is mcls:
https://github.com/python/cpython/blob/master/Lib/abc.py#L84

But, there are also cases of metacls and cls. I think it'd be safest to not validate the name in a metaclass at all, as it seems like it's not covered by PEP 8, and lacks a clear consensus on the appropriate name.

@sigmavirus24
Copy link
Member

It doesn't explicitly mention it, no, but it does mention implicitly class methods (which I think __new__ technically is).

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

No branches or pull requests

2 participants