]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Convert "__init__ should return None" from an exception to a warning.
authorRaymond Hettinger <python@rcn.com>
Fri, 4 Mar 2005 04:47:04 +0000 (04:47 +0000)
committerRaymond Hettinger <python@rcn.com>
Fri, 4 Mar 2005 04:47:04 +0000 (04:47 +0000)
Lib/test/test_descr.py
Objects/typeobject.c

index 26df0f2724e2c107a6fb0c9c05702cf1523c552a..4af59b000da8bf37c69f562a07cf1b9aaa361fcc 100644 (file)
@@ -3965,17 +3965,23 @@ def vicious_descriptor_nonsense():
     import gc; gc.collect()
     vereq(hasattr(c, 'attr'), False)
 
+import warnings
+
 def test_init():
     # SF 1155938
     class Foo(object):
         def __init__(self):
             return 10
+
+    oldfilters = warnings.filters
+    warnings.filterwarnings("error", category=RuntimeWarning)
     try:
         Foo()
-    except TypeError:
+    except RuntimeWarning:
         pass
     else:
         raise TestFailed, "did not test __init__() for None return"
+    warnings.filters = oldfilters
 
 
 def test_main():
index 6c31c73f706c14592909335ac173837b10156c5b..26fe2a19534785b53e32a206f99f7586773435d2 100644 (file)
@@ -4754,10 +4754,11 @@ slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
        if (res == NULL)
                return -1;
        if (res != Py_None) {
-               PyErr_SetString(PyExc_TypeError,
-                          "__init__() should return None");
-               Py_DECREF(res);
-               return -1;
+               if (PyErr_Warn(PyExc_RuntimeWarning, 
+                       "__init__() should return None") == -1) {
+                       Py_DECREF(res);
+                       return -1;
+               }
        }
        Py_DECREF(res);
        return 0;