pep8-naming
pep8-naming copied to clipboard
Should be cls in metaclass
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.
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.
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.
It doesn't explicitly mention it, no, but it does mention implicitly class methods (which I think __new__
technically is).