diff options
author | Cubicpath <Cubicpath@protonmail.com> | 2022-11-19 08:52:54 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-19 14:52:54 +0100 |
commit | 44d51b022a1378fb486a4655490bbe7585098189 (patch) | |
tree | fd1fe56e84f5b61642f5f7014bad1857ed11e05d | |
parent | 53974e8e6711cec3e5659c26855cec6fada5a9cf (diff) | |
download | pylint-git-44d51b022a1378fb486a4655490bbe7585098189.tar.gz |
Fix `valid-metaclass-classmethod-first-arg` default value (#7791)
* Change default value to "mcs"
* Fix functional tests to use "mcs" for first MetaClass classmethod arg
-rw-r--r-- | doc/user_guide/configuration/all-options.rst | 4 | ||||
-rw-r--r-- | doc/whatsnew/fragments/7782.bugfix | 4 | ||||
-rw-r--r-- | examples/pylintrc | 2 | ||||
-rw-r--r-- | examples/pyproject.toml | 2 | ||||
-rw-r--r-- | pylint/checkers/classes/class_checker.py | 2 | ||||
-rw-r--r-- | tests/functional/c/class_members_py30.py | 2 | ||||
-rw-r--r-- | tests/functional/c/ctor_arguments.py | 4 | ||||
-rw-r--r-- | tests/functional/f/first_arg.py | 2 | ||||
-rw-r--r-- | tests/functional/f/first_arg.txt | 4 | ||||
-rw-r--r-- | tests/functional/r/regression_02/regression_too_many_arguments_2335.py | 4 | ||||
-rw-r--r-- | tests/functional/u/undefined/undefined_variable_py30.py | 4 |
11 files changed, 19 insertions, 15 deletions
diff --git a/doc/user_guide/configuration/all-options.rst b/doc/user_guide/configuration/all-options.rst index da0ce4669..b4e40bb1a 100644 --- a/doc/user_guide/configuration/all-options.rst +++ b/doc/user_guide/configuration/all-options.rst @@ -620,7 +620,7 @@ Standard Checkers """"""""""""""""""""""""""""""""""""""" *List of valid names for the first argument in a metaclass class method.* -**Default:** ``('cls',)`` +**Default:** ``('mcs',)`` @@ -642,7 +642,7 @@ Standard Checkers valid-classmethod-first-arg = ["cls"] - valid-metaclass-classmethod-first-arg = ["cls"] + valid-metaclass-classmethod-first-arg = ["mcs"] diff --git a/doc/whatsnew/fragments/7782.bugfix b/doc/whatsnew/fragments/7782.bugfix new file mode 100644 index 000000000..e4c1498c4 --- /dev/null +++ b/doc/whatsnew/fragments/7782.bugfix @@ -0,0 +1,4 @@ +Fix ``valid-metaclass-classmethod-first-arg`` default config value from "cls" to "mcs" +which would cause both a false-positive and false-negative. + +Closes #7782 diff --git a/examples/pylintrc b/examples/pylintrc index 608a8f269..61a9361d6 100644 --- a/examples/pylintrc +++ b/examples/pylintrc @@ -260,7 +260,7 @@ exclude-protected=_asdict, valid-classmethod-first-arg=cls # List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=cls +valid-metaclass-classmethod-first-arg=mcs [DESIGN] diff --git a/examples/pyproject.toml b/examples/pyproject.toml index c02538a7c..98cb39bb9 100644 --- a/examples/pyproject.toml +++ b/examples/pyproject.toml @@ -222,7 +222,7 @@ exclude-protected = ["_asdict", "_fields", "_replace", "_source", "_make"] valid-classmethod-first-arg = ["cls"] # List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg = ["cls"] +valid-metaclass-classmethod-first-arg = ["mcs"] [tool.pylint.design] # List of regular expressions of class ancestor names to ignore when counting diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py index 47142ba96..e2806ef43 100644 --- a/pylint/checkers/classes/class_checker.py +++ b/pylint/checkers/classes/class_checker.py @@ -792,7 +792,7 @@ a class method.", ( "valid-metaclass-classmethod-first-arg", { - "default": ("cls",), + "default": ("mcs",), "type": "csv", "metavar": "<argument names>", "help": "List of valid names for the first argument in \ diff --git a/tests/functional/c/class_members_py30.py b/tests/functional/c/class_members_py30.py index 0d65331f9..4566ff44e 100644 --- a/tests/functional/c/class_members_py30.py +++ b/tests/functional/c/class_members_py30.py @@ -37,7 +37,7 @@ class TestMetaclass(metaclass=ABCMeta): class Metaclass(type):
""" metaclass """
@classmethod
- def test(cls):
+ def test(mcs):
""" classmethod """
class UsingMetaclass(metaclass=Metaclass):
diff --git a/tests/functional/c/ctor_arguments.py b/tests/functional/c/ctor_arguments.py index 954d9b8b2..d87732f1d 100644 --- a/tests/functional/c/ctor_arguments.py +++ b/tests/functional/c/ctor_arguments.py @@ -65,8 +65,8 @@ ClassNew(one=2) # [no-value-for-parameter,unexpected-keyword-arg] class Metaclass(type): - def __new__(cls, name, bases, namespace): - return type.__new__(cls, name, bases, namespace) + def __new__(mcs, name, bases, namespace): + return type.__new__(mcs, name, bases, namespace) def with_metaclass(meta, base=object): """Create a new type that can be used as a metaclass.""" diff --git a/tests/functional/f/first_arg.py b/tests/functional/f/first_arg.py index d8007e144..ac5c6bcf6 100644 --- a/tests/functional/f/first_arg.py +++ b/tests/functional/f/first_arg.py @@ -31,7 +31,7 @@ class Meta(type): pass # C0205, metaclass classmethod - def class1(cls): + def class1(mcs): pass class1 = classmethod(class1) # [no-classmethod-decorator] diff --git a/tests/functional/f/first_arg.txt b/tests/functional/f/first_arg.txt index 26aabd22e..3bfb8a0f5 100644 --- a/tests/functional/f/first_arg.txt +++ b/tests/functional/f/first_arg.txt @@ -2,8 +2,8 @@ bad-classmethod-argument:8:4:8:15:Obj.__new__:Class method __new__ should have ' no-classmethod-decorator:14:4:14:10:Obj:Consider using a decorator instead of calling classmethod:UNDEFINED bad-classmethod-argument:16:4:16:14:Obj.class2:Class method class2 should have 'cls' as first argument:UNDEFINED no-classmethod-decorator:18:4:18:10:Obj:Consider using a decorator instead of calling classmethod:UNDEFINED -bad-mcs-classmethod-argument:23:4:23:15:Meta.__new__:Metaclass class method __new__ should have 'cls' as first argument:UNDEFINED +bad-mcs-classmethod-argument:23:4:23:15:Meta.__new__:Metaclass class method __new__ should have 'mcs' as first argument:UNDEFINED bad-mcs-method-argument:30:4:30:15:Meta.method2:Metaclass method method2 should have 'cls' as first argument:UNDEFINED no-classmethod-decorator:36:4:36:10:Meta:Consider using a decorator instead of calling classmethod:UNDEFINED -bad-mcs-classmethod-argument:38:4:38:14:Meta.class2:Metaclass class method class2 should have 'cls' as first argument:UNDEFINED +bad-mcs-classmethod-argument:38:4:38:14:Meta.class2:Metaclass class method class2 should have 'mcs' as first argument:UNDEFINED no-classmethod-decorator:40:4:40:10:Meta:Consider using a decorator instead of calling classmethod:UNDEFINED diff --git a/tests/functional/r/regression_02/regression_too_many_arguments_2335.py b/tests/functional/r/regression_02/regression_too_many_arguments_2335.py index d2759adfe..55aa87308 100644 --- a/tests/functional/r/regression_02/regression_too_many_arguments_2335.py +++ b/tests/functional/r/regression_02/regression_too_many_arguments_2335.py @@ -7,5 +7,5 @@ from abc import ABCMeta class NodeCheckMetaClass(ABCMeta): - def __new__(cls, name, bases, namespace, **kwargs): - return ABCMeta.__new__(cls, name, bases, namespace) + def __new__(mcs, name, bases, namespace, **kwargs): + return ABCMeta.__new__(mcs, name, bases, namespace) diff --git a/tests/functional/u/undefined/undefined_variable_py30.py b/tests/functional/u/undefined/undefined_variable_py30.py index 0b5aa0422..ff77aaf8e 100644 --- a/tests/functional/u/undefined/undefined_variable_py30.py +++ b/tests/functional/u/undefined/undefined_variable_py30.py @@ -89,9 +89,9 @@ def used_before_assignment(*, arg): return arg + 1 # Test for #4021 # https://github.com/PyCQA/pylint/issues/4021 class MetaClass(type): - def __new__(cls, *args, parameter=None, **kwargs): + def __new__(mcs, *args, parameter=None, **kwargs): print(parameter) - return super().__new__(cls, *args, **kwargs) + return super().__new__(mcs, *args, **kwargs) class InheritingClass(metaclass=MetaClass, parameter=variable): # [undefined-variable] |