[Python-3000-checkins] r58107 - in python/branches/py3k/Lib: abc.py test/test_abc.py
guido.van.rossum
python-3000-checkins at python.org
Tue Sep 11 22:42:31 CEST 2007
Author: guido.van.rossum
Date: Tue Sep 11 22:42:30 2007
New Revision: 58107
Modified:
python/branches/py3k/Lib/abc.py
python/branches/py3k/Lib/test/test_abc.py
Log:
Thomas Wouters pointed out that _Abstract.__new__ should use super().__new__()
instead of going straight to object.__new__().
Modified: python/branches/py3k/Lib/abc.py
==============================================================================
--- python/branches/py3k/Lib/abc.py (original)
+++ python/branches/py3k/Lib/abc.py Tue Sep 11 22:42:30 2007
@@ -56,8 +56,6 @@
"""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 @@
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):
Modified: python/branches/py3k/Lib/test/test_abc.py
==============================================================================
--- python/branches/py3k/Lib/test/test_abc.py (original)
+++ python/branches/py3k/Lib/test/test_abc.py Tue Sep 11 22:42:30 2007
@@ -130,6 +130,20 @@
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)
More information about the Python-3000-checkins
mailing list