Commits

Raymond Hettinger  committed 903045a

Convert "__init__ should return None" from an exception to a warning.

  • Participants
  • Parent commits ed6ec00
  • Branches 2.4

Comments (0)

Files changed (2)

File Lib/test/test_descr.py

     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():

File Objects/typeobject.c

 	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;