summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniël van Noord <13665637+DanielNoord@users.noreply.github.com>2022-04-04 20:19:26 +0200
committerDaniël van Noord <13665637+DanielNoord@users.noreply.github.com>2022-04-04 20:21:46 +0200
commitaea58d6e25484d404ef9ed570e36631944b237ea (patch)
tree424521faaec660b8807206fccd0b8e36ee64ddf0
parentda50950a958e162513554961f3cceca2467021c0 (diff)
downloadpylint-git-aea58d6e25484d404ef9ed570e36631944b237ea.tar.gz
Deprecate ``ignore-mixin-members`` + add ``ignored-checks-for-mixins``
-rw-r--r--ChangeLog5
-rw-r--r--doc/faq.rst7
-rw-r--r--doc/whatsnew/2.14.rst5
-rw-r--r--examples/pylintrc4
-rw-r--r--pylint/checkers/async.py12
-rw-r--r--pylint/checkers/classes/class_checker.py10
-rw-r--r--pylint/checkers/typecheck.py27
-rw-r--r--pylint/utils/utils.py1
-rw-r--r--pylintrc4
-rw-r--r--tests/functional/m/mixin_class_rgx.rc1
10 files changed, 48 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index 4478f46ef..725500b9f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -46,6 +46,11 @@ Release date: TBA
Closes #578
+* The ``ignore-mixin-members`` option has been deprecated. You should now use the new
+ ``ignored-checks-for-mixins`` option.
+
+ Closes #5205
+
* Added new checker ``unnecessary-list-index-lookup`` for indexing into a list while
iterating over ``enumerate()``.
diff --git a/doc/faq.rst b/doc/faq.rst
index 04e3b1493..de7288ae5 100644
--- a/doc/faq.rst
+++ b/doc/faq.rst
@@ -257,10 +257,9 @@ methods is doing nothing but raising NotImplementedError.
5.2 How do I avoid "access to undefined member" messages in my mixin classes?
-------------------------------------------------------------------------------
-To do so you have to set the ignore-mixin-members option to
-"yes" (this is the default value) and name your mixin class with
-a name which ends with "Mixin" or "mixin" (default) or change the
-default value by changing the mixin-class-rgx option.
+You should add the ``no-member`` message to your ``ignored-checks-for-mixins`` option
+and name your mixin class with a name which ends with "Mixin" or "mixin" (default)
+or change the default value by changing the ``mixin-class-rgx`` option.
6. Troubleshooting
diff --git a/doc/whatsnew/2.14.rst b/doc/whatsnew/2.14.rst
index 486a1a0f9..82a9e7e1a 100644
--- a/doc/whatsnew/2.14.rst
+++ b/doc/whatsnew/2.14.rst
@@ -73,6 +73,11 @@ Other Changes
* The ``set_config_directly`` decorator has been removed.
+* The ``ignore-mixin-members`` option has been deprecated. You should now use the new
+ ``ignored-checks-for-mixins`` option.
+
+ Closes #5205
+
* Fix false negative for ``no-member`` when attempting to assign an instance
attribute to itself without any prior assignment.
diff --git a/examples/pylintrc b/examples/pylintrc
index 8fb3c179a..9c3692799 100644
--- a/examples/pylintrc
+++ b/examples/pylintrc
@@ -178,10 +178,6 @@ contextmanager-decorators=contextlib.contextmanager
# expressions are accepted.
generated-members=
-# Tells whether missing members accessed in mixin class should be ignored. A
-# mixin class is detected if its name ends with "mixin" (case insensitive).
-ignore-mixin-members=yes
-
# Tells whether to warn about missing members when the owner of the attribute
# is inferred to be None.
ignore-none=yes
diff --git a/pylint/checkers/async.py b/pylint/checkers/async.py
index a85ab4117..d9a9232f7 100644
--- a/pylint/checkers/async.py
+++ b/pylint/checkers/async.py
@@ -38,10 +38,10 @@ class AsyncChecker(checkers.BaseChecker):
),
}
+ def __init__(self, linter: "PyLinter") -> None:
+ super().__init__(linter, future_option_parsing=True)
+
def open(self):
- self._ignore_mixin_members = utils.get_global_option(
- self, "ignore-mixin-members"
- )
self._mixin_class_rgx = utils.get_global_option(self, "mixin-class-rgx")
self._async_generators = ["contextlib.asynccontextmanager"]
@@ -81,8 +81,10 @@ class AsyncChecker(checkers.BaseChecker):
if not checker_utils.has_known_bases(inferred):
continue
# Ignore mixin classes if they match the rgx option.
- if self._ignore_mixin_members and self._mixin_class_rgx.match(
- inferred.name
+ if (
+ "not-async-context-manager"
+ in self.linter.namespace.ignored_checks_for_mixins
+ and self._mixin_class_rgx.match(inferred.name)
):
continue
else:
diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py
index 4c8bd2cfb..7a3c58df3 100644
--- a/pylint/checkers/classes/class_checker.py
+++ b/pylint/checkers/classes/class_checker.py
@@ -780,10 +780,6 @@ a metaclass class method.",
def _dummy_rgx(self):
return get_global_option(self, "dummy-variables-rgx", default=None)
- @cached_property
- def _ignore_mixin(self):
- return get_global_option(self, "ignore-mixin-members", default=True)
-
@check_messages(
"abstract-method",
"no-init",
@@ -1026,7 +1022,11 @@ a metaclass class method.",
def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
# check access to existent members on non metaclass classes
- if self._ignore_mixin and self._mixin_class_rgx.match(cnode.name):
+ if (
+ "attribute-defined-outside-init"
+ in self.linter.namespace.ignored_checks_for_mixins
+ and self._mixin_class_rgx.match(cnode.name)
+ ):
# We are in a mixin class. No need to try to figure out if
# something is missing, since it is most likely that it will
# miss.
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py
index 98af20e53..2ab5ced33 100644
--- a/pylint/checkers/typecheck.py
+++ b/pylint/checkers/typecheck.py
@@ -764,8 +764,7 @@ class TypeChecker(BaseChecker):
"default": ".*[Mm]ixin",
"type": "regexp",
"metavar": "<regexp>",
- "help": "Regex pattern to define which classes are considered mixins "
- "ignore-mixin-members is set to 'yes'",
+ "help": "Regex pattern to define which classes are considered mixins.",
},
),
(
@@ -777,6 +776,21 @@ class TypeChecker(BaseChecker):
"help": "Tells whether missing members accessed in mixin "
"class should be ignored. A class is considered mixin if its name matches "
"the mixin-class-rgx option.",
+ "kwargs": {"new_names": ["ignore-checks-for-mixin"]},
+ },
+ ),
+ (
+ "ignored-checks-for-mixins",
+ {
+ "default": [
+ "no-member",
+ "not-async-context-manager",
+ "not-context-manager",
+ "attribute-defined-outside-init",
+ ],
+ "type": "csv",
+ "metavar": "<list of messages names>",
+ "help": "List of symbolic message names to ignore for Mixin members.",
},
),
(
@@ -1030,7 +1044,9 @@ accessed. Python regular expressions are accepted.",
owner,
name,
self._mixin_class_rgx,
- ignored_mixins=self.linter.namespace.ignore_mixin_members,
+ ignored_mixins=(
+ "no-member" in self.linter.namespace.ignored_checks_for_mixins
+ ),
ignored_none=self.linter.namespace.ignore_none,
):
continue
@@ -1762,7 +1778,10 @@ accessed. Python regular expressions are accepted.",
if not has_known_bases(inferred):
continue
# Just ignore mixin classes.
- if self.linter.namespace.ignore_mixin_members:
+ if (
+ "not-context-manager"
+ in self.linter.namespace.ignored_checks_for_mixins
+ ):
if inferred.name[-5:].lower() == "mixin":
continue
diff --git a/pylint/utils/utils.py b/pylint/utils/utils.py
index 90a082daf..d7222b42f 100644
--- a/pylint/utils/utils.py
+++ b/pylint/utils/utils.py
@@ -49,7 +49,6 @@ DEFAULT_LINE_LENGTH = 79
# These are types used to overload get_global_option() and refer to the options type
GLOBAL_OPTION_BOOL = Literal[
- "ignore-mixin-members",
"suggestion-mode",
"analyse-fallback-blocks",
"allow-global-unused-variables",
diff --git a/pylintrc b/pylintrc
index 902b3e9c2..c48162362 100644
--- a/pylintrc
+++ b/pylintrc
@@ -371,10 +371,6 @@ property-classes=abc.abstractproperty
[TYPECHECK]
-# Tells whether missing members accessed in mixin class should be ignored.
-# A class is considered mixin if its name matches the mixin-class-rgx option.
-ignore-mixin-members=yes
-
# Regex pattern to define which classes are considered mixins if ignore-mixin-
# members is set to 'yes'
mixin-class-rgx=.*MixIn
diff --git a/tests/functional/m/mixin_class_rgx.rc b/tests/functional/m/mixin_class_rgx.rc
index 4ca300e4a..df59c20d9 100644
--- a/tests/functional/m/mixin_class_rgx.rc
+++ b/tests/functional/m/mixin_class_rgx.rc
@@ -1,3 +1,2 @@
[TYPECHECK]
-ignore-mixin-members=yes
mixin-class-rgx=.*[Mm]ixin