diff options
author | Raymond Hettinger <python@rcn.com> | 2005-03-04 04:47:04 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2005-03-04 04:47:04 (GMT) |
commit | ace3f61994a7ea5e9284d4297a5a90307be23179 (patch) | |
tree | e6e7884121ce74c8d39be6b11c36939126b93765 | |
parent | f05d1c0099fa3f5a46b0d9b0eb709db3bbb6cf2f (diff) | |
download | cpython-ace3f61994a7ea5e9284d4297a5a90307be23179.zip cpython-ace3f61994a7ea5e9284d4297a5a90307be23179.tar.gz cpython-ace3f61994a7ea5e9284d4297a5a90307be23179.tar.bz2 |
Convert "__init__ should return None" from an exception to a warning.
-rw-r--r-- | Lib/test/test_descr.py | 8 | ||||
-rw-r--r-- | Objects/typeobject.c | 9 |
2 files changed, 12 insertions, 5 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 26df0f2..4af59b0 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -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(): diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 6c31c73..26fe2a1 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -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; |