summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2015-10-21 22:52:16 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2015-10-21 22:52:16 +0100
commit525a54d010f04157cb2d63768f9a1853783ffbf4 (patch)
tree33ccff1eb27fe09f4081e0c2b4d3bd0143c0b4fe
parent9c29e8041fa4ff49e3d4212bb0977c65293587cd (diff)
downloadpylint-525a54d010f04157cb2d63768f9a1853783ffbf4.tar.gz
Don't warn about abstract classes instantiated in their own body. Closes issue #627.
-rw-r--r--ChangeLog3
-rw-r--r--pylint/checkers/base.py11
-rw-r--r--pylint/test/functional/abstract_class_instantiated_in_class.py20
3 files changed, 34 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 7424066..2003d86 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,9 @@ ChangeLog for Pylint
--
+ * Don't warn about abstract classes instantiated in their own
+ body. Closes issue #627.
+
* Obsolete options are not present by default in the generated
configuration file. Closes issue #632.
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py
index 927e77b..b9955e3 100644
--- a/pylint/checkers/base.py
+++ b/pylint/checkers/base.py
@@ -41,6 +41,7 @@ from pylint.checkers.utils import (
is_inside_except,
overrides_a_method,
get_argument_from_call,
+ node_frame_class,
NoSuchArgumentError,
error_of_type,
unimplemented_abstract_methods,
@@ -497,8 +498,18 @@ class BasicErrorChecker(_BasicChecker):
infered = next(node.func.infer())
except astroid.InferenceError:
return
+
if not isinstance(infered, astroid.ClassDef):
return
+
+ klass = node_frame_class(node)
+ if klass is infered:
+ # Don't emit the warning if the class is instantiated
+ # in its own body or if the call is not an instance
+ # creation. If the class is instantiated into its own
+ # body, we're expecting that it knows what it is doing.
+ return
+
# __init__ was called
metaclass = infered.metaclass()
abstract_methods = _has_abstract_methods(infered)
diff --git a/pylint/test/functional/abstract_class_instantiated_in_class.py b/pylint/test/functional/abstract_class_instantiated_in_class.py
new file mode 100644
index 0000000..9402c12
--- /dev/null
+++ b/pylint/test/functional/abstract_class_instantiated_in_class.py
@@ -0,0 +1,20 @@
+"""Don't warn if the class is instantiated in its own body."""
+# pylint: disable=missing-docstring
+
+
+import abc
+
+import six
+
+
+@six.add_metaclass(abc.ABCMeta)
+class Ala(object):
+
+ @abc.abstractmethod
+ def bala(self):
+ pass
+
+ @classmethod
+ def portocala(cls):
+ instance = cls()
+ return instance