Commits

Anonymous committed 9b3a2c4

SF bug #1155938: Missing None check for __init__().

Comments (0)

Files changed (3)

Lib/test/test_descr.py

     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
     carloverre()
     filefault()
     vicious_descriptor_nonsense()
+    test_init()
 
     if verbose: print "All OK"
 
 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

Objects/typeobject.c

 	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;
 }