summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-03-03 16:55:53 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-03-03 16:55:53 (GMT)
commit2a06df625837867f8595de7bd334f401f6ab2a85 (patch)
treef6689d29705a89337f22a1dbf3d524d8a981d413
parent77c8402c97092b5520ac13ad4ffa4417a08a8db9 (diff)
downloadcpython-2a06df625837867f8595de7bd334f401f6ab2a85.zip
cpython-2a06df625837867f8595de7bd334f401f6ab2a85.tar.gz
cpython-2a06df625837867f8595de7bd334f401f6ab2a85.tar.bz2
SF bug #1155938: Missing None check for __init__().
-rw-r--r--Lib/test/test_descr.py13
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/typeobject.c6
3 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index f1abd3a..26df0f2 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -3965,6 +3965,18 @@ def vicious_descriptor_nonsense():
import gc; gc.collect()
vereq(hasattr(c, 'attr'), False)
+def test_init():
+ # SF 1155938
+ class Foo(object):
+ def __init__(self):
+ return 10
+ try:
+ Foo()
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "did not test __init__() for None return"
+
def test_main():
weakref_segfault() # Must be first, somehow
@@ -4058,6 +4070,7 @@ def test_main():
carloverre()
filefault()
vicious_descriptor_nonsense()
+ test_init()
if verbose: print "All OK"
diff --git a/Misc/NEWS b/Misc/NEWS
index c8ab678..b3cabe9 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.4.1?
Core and builtins
-----------------
+- Bug #1155938: new style classes did not verify that __init__()
+ returns None.
+
- Bug #723201: Raise a TypeError for passing bad objects to 'L' format.
- Bug #1124295: the __name__ attribute of file objects was
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 600dca5..6c31c73 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -4753,6 +4753,12 @@ slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
Py_DECREF(meth);
if (res == NULL)
return -1;
+ if (res != Py_None) {
+ PyErr_SetString(PyExc_TypeError,
+ "__init__() should return None");
+ Py_DECREF(res);
+ return -1;
+ }
Py_DECREF(res);
return 0;
}