summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2014-11-15 14:20:00 +0200
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2014-11-15 14:20:00 +0200
commita908de679b57447508391ee2c0c76b4a8e24bf3f (patch)
tree56aa44fbbdedc03d92dfe3b987da8368d35be11f
parent6a44a9f8d9af506734671bb540985ba399562136 (diff)
downloadpylint-a908de679b57447508391ee2c0c76b4a8e24bf3f.tar.gz
abstract-class-instantiated is also emitted for Python 2.
-rw-r--r--ChangeLog3
-rw-r--r--checkers/base.py3
-rw-r--r--test/input/func_abstract_class_instantiated_py_30.py67
-rw-r--r--test/messages/func_abstract_class_instantiated_py_30.txt5
4 files changed, 76 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 516234b..ebe2532 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -166,6 +166,9 @@ ChangeLog for Pylint
* Warn when performing parameter tuple unpacking; it is not supported in
Python 3.
+ * 'abstract-class-instantiated' is also emitted for Python 2.
+ It was previously disabled.
+
2014-07-26 -- 1.3.0
diff --git a/checkers/base.py b/checkers/base.py
index 0271592..5392df8 100644
--- a/checkers/base.py
+++ b/checkers/base.py
@@ -290,8 +290,7 @@ class BasicErrorChecker(_BasicChecker):
'E0110': ('Abstract class with abstract methods instantiated',
'abstract-class-instantiated',
'Used when an abstract class with `abc.ABCMeta` as metaclass '
- 'has abstract methods and is instantiated.',
- {'minversion': (3, 0)}),
+ 'has abstract methods and is instantiated.'),
'W0120': ('Else clause on loop without a break statement',
'useless-else-on-loop',
'Loops should only have an else clause if they can exit early '
diff --git a/test/input/func_abstract_class_instantiated_py_30.py b/test/input/func_abstract_class_instantiated_py_30.py
new file mode 100644
index 0000000..97e33f2
--- /dev/null
+++ b/test/input/func_abstract_class_instantiated_py_30.py
@@ -0,0 +1,67 @@
+"""Check that instantiating a class with
+`abc.ABCMeta` as metaclass fails if it defines
+abstract methods.
+"""
+
+# pylint: disable=too-few-public-methods, missing-docstring, abstract-class-not-used
+# pylint: disable=no-absolute-import, metaclass-assignment, abstract-class-little-used
+
+__revision__ = 0
+
+import abc
+from abc import ABCMeta
+
+class GoodClass(object):
+ __metaclass__ = abc.ABCMeta
+
+class SecondGoodClass(object):
+ __metaclass__ = abc.ABCMeta
+
+ def test(self):
+ """ do nothing. """
+
+class ThirdGoodClass(object):
+ __metaclass__ = abc.ABCMeta
+
+ def test(self):
+ raise NotImplementedError()
+
+class FourthGoodClass(object):
+ __metaclass__ = ABCMeta
+
+class BadClass(object):
+ __metaclass__ = abc.ABCMeta
+
+ @abc.abstractmethod
+ def test(self):
+ """ do nothing. """
+
+class SecondBadClass(object):
+ __metaclass__ = abc.ABCMeta
+
+ @property
+ @abc.abstractmethod
+ def test(self):
+ """ do nothing. """
+
+class ThirdBadClass(object):
+ __metaclass__ = ABCMeta
+
+ @abc.abstractmethod
+ def test(self):
+ pass
+
+class FourthBadClass(ThirdBadClass):
+ pass
+
+
+def main():
+ """ do nothing """
+ GoodClass()
+ SecondGoodClass()
+ ThirdGoodClass()
+ FourthGoodClass()
+ BadClass()
+ SecondBadClass()
+ ThirdBadClass()
+ FourthBadClass()
diff --git a/test/messages/func_abstract_class_instantiated_py_30.txt b/test/messages/func_abstract_class_instantiated_py_30.txt
new file mode 100644
index 0000000..0e2b268
--- /dev/null
+++ b/test/messages/func_abstract_class_instantiated_py_30.txt
@@ -0,0 +1,5 @@
+E: 64:main: Abstract class with abstract methods instantiated
+E: 65:main: Abstract class with abstract methods instantiated
+E: 66:main: Abstract class with abstract methods instantiated
+E: 67:main: Abstract class with abstract methods instantiated
+W: 54:FourthBadClass: Method 'test' is abstract in class 'ThirdBadClass' but is not overridden \ No newline at end of file