summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--pylint/checkers/classes.py10
-rw-r--r--pylint/test/functional/access_member_before_definition.py9
-rw-r--r--pylint/test/functional/attribute_defined_outside_init.py8
4 files changed, 30 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index b52bcc6fd..6637f6eac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -111,6 +111,10 @@ ChangeLog for Pylint
which is totally misleading, it now emits undefined-variable.
Closes issue #528.
+ * Don't emit attribute-defined-outside-init and access-member-before-definition
+ for mixin classes. Actual errors can occur in mixin classes, but this is
+ controlled by the ignore-mixin-members option. Closes issue #412.
+
2015-03-14 -- 1.4.3
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py
index 060e16685..9c5ba9f35 100644
--- a/pylint/checkers/classes.py
+++ b/pylint/checkers/classes.py
@@ -31,7 +31,7 @@ from pylint.checkers.utils import (
PYMETHODS, overrides_a_method, check_messages, is_attr_private,
is_attr_protected, node_frame_class, safe_infer, is_builtin_object,
decorated_with_property, unimplemented_abstract_methods)
-from pylint.utils import deprecated_option
+from pylint.utils import deprecated_option, get_global_option
import six
if sys.version_info >= (3, 0):
@@ -341,6 +341,14 @@ a metaclass class method.'}
access to existent members
"""
# check access to existent members on non metaclass classes
+ ignore_mixins = get_global_option(self, 'ignore-mixin-members',
+ default=True)
+ if ignore_mixins and cnode.name[-5:].lower() == 'mixin':
+ # 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.
+ return
+
accessed = self._accessed.pop()
if cnode.type != 'metaclass':
self._check_accessed_members(cnode, accessed)
diff --git a/pylint/test/functional/access_member_before_definition.py b/pylint/test/functional/access_member_before_definition.py
index 60d74869f..53294fbce 100644
--- a/pylint/test/functional/access_member_before_definition.py
+++ b/pylint/test/functional/access_member_before_definition.py
@@ -29,3 +29,12 @@ class Bbbb(object):
except ValueError:
self._repo = attr
return attr
+
+
+class Mixin(object):
+
+ def test_mixin(self):
+ """Don't emit access-member-before-definition for mixin classes."""
+ if self.already_defined:
+ # pylint: disable=attribute-defined-outside-init
+ self.already_defined = None
diff --git a/pylint/test/functional/attribute_defined_outside_init.py b/pylint/test/functional/attribute_defined_outside_init.py
index 917cb432c..912bc459f 100644
--- a/pylint/test/functional/attribute_defined_outside_init.py
+++ b/pylint/test/functional/attribute_defined_outside_init.py
@@ -52,3 +52,11 @@ class E(object):
def _init(self):
self.z = 44
+
+
+class Mixin(object):
+
+ def test_mixin(self):
+ """Don't emit attribute-defined-outside-init for mixin classes."""
+ if self.defined_already: # pylint: disable=access-member-before-definition
+ self.defined_already = None