finally:
sys.stdout = save_stdout
+ def test_del_stdout_before_print(self):
+ # Issue 4597: 'print' with no argument wasn't reporting when
+ # sys.stdout was deleted.
+ save_stdout = sys.stdout
+ del sys.stdout
+ try:
+ print
+ except RuntimeError as e:
+ self.assertEquals(str(e), "lost sys.stdout")
+ else:
+ self.fail("Expected RuntimeError")
+ finally:
+ sys.stdout = save_stdout
+
def test_main():
# Historically, these tests have been sloppy about removing TESTFN.
Core and Builtins
-----------------
-- Issue #4597: Fixed exception handling when the __exit__ function of a
+- Issue #4597: Fixed several opcodes that weren't always propagating
+ exceptions.
+
+- Issue #4589: Fixed exception handling when the __exit__ function of a
context manager returns a value that cannot be converted to a bool.
- Issue #4233: Changed semantic of ``_fileio.FileIO``'s ``close()``
}
Py_FatalError("invalid argument to DUP_TOPX"
" (bytecode corruption?)");
+ /* Never returns, so don't bother to set why. */
break;
case UNARY_POSITIVE:
case PRINT_NEWLINE:
if (stream == NULL || stream == Py_None) {
w = PySys_GetObject("stdout");
- if (w == NULL)
+ if (w == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"lost sys.stdout");
+ why = WHY_EXCEPTION;
+ }
}
if (w != NULL) {
/* w.write() may replace sys.stdout, so we
PyErr_Format(PyExc_SystemError,
"no locals when loading %s",
PyObject_REPR(w));
+ why = WHY_EXCEPTION;
break;
}
if (PyDict_CheckExact(v)) {
Py_DECREF(v);
if (x != NULL) {
v = POP();
- err = PyFunction_SetClosure(x, v);
+ if (PyFunction_SetClosure(x, v) != 0) {
+ /* Can't happen unless bytecode is corrupt. */
+ why = WHY_EXCEPTION;
+ }
Py_DECREF(v);
}
if (x != NULL && oparg > 0) {
w = POP();
PyTuple_SET_ITEM(v, oparg, w);
}
- err = PyFunction_SetDefaults(x, v);
+ if (PyFunction_SetDefaults(x, v) != 0) {
+ /* Can't happen unless
+ PyFunction_SetDefaults changes. */
+ why = WHY_EXCEPTION;
+ }
Py_DECREF(v);
}
PUSH(x);