[Python-3000-checkins] r62157 - in python/branches/py3k: Lib/test/test_builtin.py Python/pythonrun.c
amaury.forgeotdarc
python-3000-checkins at python.org
Sat Apr 5 01:25:28 CEST 2008
Author: amaury.forgeotdarc
Date: Sat Apr 5 01:25:27 2008
New Revision: 62157
Modified:
python/branches/py3k/Lib/test/test_builtin.py
python/branches/py3k/Python/pythonrun.c
Log:
Issue2221: in Idle, exec('xx') raised a SystemError('error return without exception set')
instead of the expected NameError
This happens when sys.stdout is redirected to something that cannot flush().
the flush_io() function must be exception-neutral: don't raise, and don't clear exceptions.
Next step: exec() is not supposed to flush sys.stdout...
Modified: python/branches/py3k/Lib/test/test_builtin.py
==============================================================================
--- python/branches/py3k/Lib/test/test_builtin.py (original)
+++ python/branches/py3k/Lib/test/test_builtin.py Sat Apr 5 01:25:27 2008
@@ -448,6 +448,17 @@
del l['__builtins__']
self.assertEqual((g, l), ({'a': 1}, {'b': 2}))
+ def test_exec_redirected(self):
+ savestdout = sys.stdout
+ sys.stdout = None # Whatever that cannot flush()
+ try:
+ # Used to raise SystemError('error return without exception set')
+ exec('a')
+ except NameError:
+ pass
+ finally:
+ sys.stdout = savestdout
+
def test_filter(self):
self.assertEqual(list(filter(lambda c: 'a' <= c <= 'z', 'Hello World')), list('elloorld'))
self.assertEqual(list(filter(None, [1, 'hello', [], [3], '', None, 9, 0])), [1, 'hello', [3], 9])
Modified: python/branches/py3k/Python/pythonrun.c
==============================================================================
--- python/branches/py3k/Python/pythonrun.c (original)
+++ python/branches/py3k/Python/pythonrun.c Sat Apr 5 01:25:27 2008
@@ -1467,6 +1467,11 @@
flush_io(void)
{
PyObject *f, *r;
+ PyObject *type, *value, *traceback;
+
+ /* Save the current exception */
+ PyErr_Fetch(&type, &value, &traceback);
+
f = PySys_GetObject("stderr");
if (f != NULL) {
r = PyObject_CallMethod(f, "flush", "");
@@ -1483,6 +1488,8 @@
else
PyErr_Clear();
}
+
+ PyErr_Restore(type, value, traceback);
}
static PyObject *
More information about the Python-3000-checkins
mailing list