]> granicus.if.org Git - python/commitdiff
Thomas Wouters pointed out that _Abstract.__new__ should use super().__new__()
authorGuido van Rossum <guido@python.org>
Tue, 11 Sep 2007 20:42:30 +0000 (20:42 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 11 Sep 2007 20:42:30 +0000 (20:42 +0000)
instead of going straight to object.__new__().

Lib/abc.py
Lib/test/test_abc.py

index ad5a52313c4b5b9fd1444ffc1fe225828f4aab55..f8e02302782b86ed691e7b58a4653df7cd80f9c2 100644 (file)
@@ -56,8 +56,6 @@ class _Abstract(object):
     """Helper class inserted into the bases by ABCMeta (using _fix_bases()).
 
     You should never need to explicitly subclass this class.
-
-    There should never be a base class between _Abstract and object.
     """
 
     def __new__(cls, *args, **kwds):
@@ -69,7 +67,7 @@ class _Abstract(object):
         if (args or kwds) and cls.__init__ is object.__init__:
             raise TypeError("Can't pass arguments to __new__ "
                             "without overriding __init__")
-        return object.__new__(cls)
+        return super().__new__(cls)
 
     @classmethod
     def __subclasshook__(cls, subclass):
index f93f3d35be0ba75fe24925f66be05e13c1c5b17c..008d8394995d5052191d5c13db313e3c6bb79ca0 100644 (file)
@@ -130,6 +130,20 @@ class TestABC(unittest.TestCase):
         self.failUnless(issubclass(MyInt, A))
         self.failUnless(isinstance(42, A))
 
+    def test_all_new_methods_are_called(self):
+        class A(metaclass=abc.ABCMeta):
+            pass
+        class B:
+            counter = 0
+            def __new__(cls):
+                B.counter += 1
+                return super().__new__(cls)
+        class C(A, B):
+            pass
+        self.assertEqual(B.counter, 0)
+        C()
+        self.assertEqual(B.counter, 1)
+
 
 def test_main():
     test_support.run_unittest(TestABC)