Skip to content

Commit 894d35e

Browse files
committed
Thomas Wouters pointed out that _Abstract.__new__ should use super().__new__()
instead of going straight to object.__new__().
1 parent 1ba3114 commit 894d35e

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

Lib/abc.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ class _Abstract(object):
5656
"""Helper class inserted into the bases by ABCMeta (using _fix_bases()).
5757
5858
You should never need to explicitly subclass this class.
59-
60-
There should never be a base class between _Abstract and object.
6159
"""
6260

6361
def __new__(cls, *args, **kwds):
@@ -69,7 +67,7 @@ def __new__(cls, *args, **kwds):
6967
if (args or kwds) and cls.__init__ is object.__init__:
7068
raise TypeError("Can't pass arguments to __new__ "
7169
"without overriding __init__")
72-
return object.__new__(cls)
70+
return super().__new__(cls)
7371

7472
@classmethod
7573
def __subclasshook__(cls, subclass):

Lib/test/test_abc.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ class MyInt(int):
130130
self.failUnless(issubclass(MyInt, A))
131131
self.failUnless(isinstance(42, A))
132132

133+
def test_all_new_methods_are_called(self):
134+
class A(metaclass=abc.ABCMeta):
135+
pass
136+
class B:
137+
counter = 0
138+
def __new__(cls):
139+
B.counter += 1
140+
return super().__new__(cls)
141+
class C(A, B):
142+
pass
143+
self.assertEqual(B.counter, 0)
144+
C()
145+
self.assertEqual(B.counter, 1)
146+
133147

134148
def test_main():
135149
test_support.run_unittest(TestABC)

0 commit comments

Comments
 (0)