mirror of https://github.com/python/cpython.git
Fix for bug [#452230] future division isn't propagated.
builtin_eval wasn't merging in the compiler flags from the current frame; I suppose we never noticed this before because future division is the first future-feature that can affect expressions (nested_scopes and generators had only statement-level effects).
This commit is contained in:
parent
a8278cc37e
commit
9fa96bed6f
|
@ -335,6 +335,7 @@ def test_future_div(self):
|
||||||
self.assertEqual(2 / Rat(5), Rat(2, 5))
|
self.assertEqual(2 / Rat(5), Rat(2, 5))
|
||||||
self.assertEqual(3.0 * Rat(1, 2), 1.5)
|
self.assertEqual(3.0 * Rat(1, 2), 1.5)
|
||||||
self.assertEqual(Rat(1, 2) * 3.0, 1.5)
|
self.assertEqual(Rat(1, 2) * 3.0, 1.5)
|
||||||
|
self.assertEqual(eval('1/2'), 0.5)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
test_support.run_unittest(RatTestCase)
|
test_support.run_unittest(RatTestCase)
|
||||||
|
|
|
@ -523,6 +523,7 @@ builtin_eval(PyObject *self, PyObject *args)
|
||||||
PyObject *cmd;
|
PyObject *cmd;
|
||||||
PyObject *globals = Py_None, *locals = Py_None;
|
PyObject *globals = Py_None, *locals = Py_None;
|
||||||
char *str;
|
char *str;
|
||||||
|
PyCompilerFlags cf;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O|O!O!:eval",
|
if (!PyArg_ParseTuple(args, "O|O!O!:eval",
|
||||||
&cmd,
|
&cmd,
|
||||||
|
@ -536,11 +537,13 @@ builtin_eval(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
else if (locals == Py_None)
|
else if (locals == Py_None)
|
||||||
locals = globals;
|
locals = globals;
|
||||||
|
|
||||||
if (PyDict_GetItemString(globals, "__builtins__") == NULL) {
|
if (PyDict_GetItemString(globals, "__builtins__") == NULL) {
|
||||||
if (PyDict_SetItemString(globals, "__builtins__",
|
if (PyDict_SetItemString(globals, "__builtins__",
|
||||||
PyEval_GetBuiltins()) != 0)
|
PyEval_GetBuiltins()) != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PyCode_Check(cmd)) {
|
if (PyCode_Check(cmd)) {
|
||||||
if (PyTuple_GET_SIZE(((PyCodeObject *)cmd)->co_freevars) > 0) {
|
if (PyTuple_GET_SIZE(((PyCodeObject *)cmd)->co_freevars) > 0) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
@ -549,6 +552,7 @@ builtin_eval(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
return PyEval_EvalCode((PyCodeObject *) cmd, globals, locals);
|
return PyEval_EvalCode((PyCodeObject *) cmd, globals, locals);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PyString_Check(cmd) &&
|
if (!PyString_Check(cmd) &&
|
||||||
!PyUnicode_Check(cmd)) {
|
!PyUnicode_Check(cmd)) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
@ -559,7 +563,10 @@ builtin_eval(PyObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
while (*str == ' ' || *str == '\t')
|
while (*str == ' ' || *str == '\t')
|
||||||
str++;
|
str++;
|
||||||
return PyRun_String(str, Py_eval_input, globals, locals);
|
|
||||||
|
cf.cf_flags = 0;
|
||||||
|
(void)PyEval_MergeCompilerFlags(&cf);
|
||||||
|
return PyRun_StringFlags(str, Py_eval_input, globals, locals, &cf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char eval_doc[] =
|
static char eval_doc[] =
|
||||||
|
|
Loading…
Reference in New Issue