summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2012-12-13 17:09:33 (GMT)
committerAndrew Svetlov <andrew.svetlov@gmail.com>2012-12-13 17:09:33 (GMT)
commitb67596d8157ef972d418e623a99c8462f485c4d6 (patch)
tree194ba5bc3fae07eaf4cf9e51197b7c8f6a114f30 /Lib
parent174bc1e309b5bde8602568f186f53d886aec757c (diff)
downloadcpython-b67596d8157ef972d418e623a99c8462f485c4d6.zip
cpython-b67596d8157ef972d418e623a99c8462f485c4d6.tar.gz
cpython-b67596d8157ef972d418e623a99c8462f485c4d6.tar.bz2
Issue #16049: add abc.ABC helper class.
Patch by Bruno Dupuis.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/abc.py6
-rw-r--r--Lib/test/test_abc.py13
2 files changed, 19 insertions, 0 deletions
diff --git a/Lib/abc.py b/Lib/abc.py
index 09778e8..e807895 100644
--- a/Lib/abc.py
+++ b/Lib/abc.py
@@ -226,3 +226,9 @@ class ABCMeta(type):
# No dice; update negative cache
cls._abc_negative_cache.add(subclass)
return False
+
+class ABC(metaclass=ABCMeta):
+ """Helper class that provides a standard way to create an ABC using
+ inheritance.
+ """
+ pass
diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py
index 653c957..3498524 100644
--- a/Lib/test/test_abc.py
+++ b/Lib/test/test_abc.py
@@ -96,6 +96,19 @@ class TestLegacyAPI(unittest.TestCase):
class TestABC(unittest.TestCase):
+ def test_ABC_helper(self):
+ # create an ABC using the helper class and perform basic checks
+ class C(abc.ABC):
+ @classmethod
+ @abc.abstractmethod
+ def foo(cls): return cls.__name__
+ self.assertEqual(type(C), abc.ABCMeta)
+ self.assertRaises(TypeError, C)
+ class D(C):
+ @classmethod
+ def foo(cls): return super().foo()
+ self.assertEqual(D.foo(), 'D')
+
def test_abstractmethod_basics(self):
@abc.abstractmethod
def foo(self): pass