]> granicus.if.org Git - python/commitdiff
SF bug #1155938: Missing None check for __init__().
authorRaymond Hettinger <python@rcn.com>
Thu, 3 Mar 2005 16:45:19 +0000 (16:45 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 3 Mar 2005 16:45:19 +0000 (16:45 +0000)
Lib/test/test_descr.py
Misc/NEWS
Objects/typeobject.c

index c1bd00d84ba46282d54e9a6f3561dedb9ce496f8..7eea465c82db9112bb3e507e5430500dacc18468 100644 (file)
@@ -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"
 
index baf344544c94315c44af1db5557b9690a1463bf9..5bf2e513fa67cf5e0b72d675268b335c88ad3a93 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 2.5 alpha 1?
 Core and builtins
 -----------------
 
+- Bug #1155938: new style classes did not check that __init__() was
+  returning None.
+
 - Patch #802188: Report characters after line continuation character 
   ('\') with a specific error message.
 
index 600dca5c93b221896aa3b619dc7fd5acd6ab76c7..6c31c73f706c14592909335ac173837b10156c5b 100644 (file)
@@ -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;
 }