mirror of
https://github.com/python/cpython.git
synced 2025-12-09 02:35:14 +00:00
SF bug #1155938: Missing None check for __init__().
This commit is contained in:
parent
6ce7ed23d0
commit
b67cc80bb9
3 changed files with 22 additions and 0 deletions
|
|
@ -3965,6 +3965,18 @@ def vicious_descriptor_nonsense():
|
||||||
import gc; gc.collect()
|
import gc; gc.collect()
|
||||||
vereq(hasattr(c, 'attr'), False)
|
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():
|
def test_main():
|
||||||
weakref_segfault() # Must be first, somehow
|
weakref_segfault() # Must be first, somehow
|
||||||
|
|
@ -4058,6 +4070,7 @@ def test_main():
|
||||||
carloverre()
|
carloverre()
|
||||||
filefault()
|
filefault()
|
||||||
vicious_descriptor_nonsense()
|
vicious_descriptor_nonsense()
|
||||||
|
test_init()
|
||||||
|
|
||||||
if verbose: print "All OK"
|
if verbose: print "All OK"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,9 @@ What's New in Python 2.5 alpha 1?
|
||||||
Core and builtins
|
Core and builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Bug #1155938: new style classes did not check that __init__() was
|
||||||
|
returning None.
|
||||||
|
|
||||||
- Patch #802188: Report characters after line continuation character
|
- Patch #802188: Report characters after line continuation character
|
||||||
('\') with a specific error message.
|
('\') with a specific error message.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4753,6 +4753,12 @@ slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
|
||||||
Py_DECREF(meth);
|
Py_DECREF(meth);
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
if (res != Py_None) {
|
||||||
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
"__init__() should return None");
|
||||||
|
Py_DECREF(res);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue