mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
Revert r82044, since it changed the semantics of negated imaginary literals.
Before r82044, '-7j' became complex(0.0, -7.0); afterwards it was complex(-0.0, -7.0). See issue 9011.
This commit is contained in:
parent
881c1b4c10
commit
ce5b6c43bf
3 changed files with 26 additions and 15 deletions
|
@ -479,16 +479,6 @@ class CompileTestCase(unittest.TestCase):
|
||||||
st = parser.suite('a = "\\u1"')
|
st = parser.suite('a = "\\u1"')
|
||||||
self.assertRaises(SyntaxError, parser.compilest, st)
|
self.assertRaises(SyntaxError, parser.compilest, st)
|
||||||
|
|
||||||
def test_issue_9011(self):
|
|
||||||
# Issue 9011: compilation of an unary minus expression changed
|
|
||||||
# the meaning of the ST, so that a second compilation produced
|
|
||||||
# incorrect results.
|
|
||||||
st = parser.expr('-3')
|
|
||||||
code1 = parser.compilest(st)
|
|
||||||
self.assertEqual(eval(code1), -3)
|
|
||||||
code2 = parser.compilest(st)
|
|
||||||
self.assertEqual(eval(code2), -3)
|
|
||||||
|
|
||||||
class ParserStackLimitTestCase(unittest.TestCase):
|
class ParserStackLimitTestCase(unittest.TestCase):
|
||||||
"""try to push the parser to/over its limits.
|
"""try to push the parser to/over its limits.
|
||||||
see http://bugs.python.org/issue1881 for a discussion
|
see http://bugs.python.org/issue1881 for a discussion
|
||||||
|
|
|
@ -16,11 +16,6 @@ Core and Builtins
|
||||||
Fix the encoding of the modules filename. Patch written by Amaury Forgeot
|
Fix the encoding of the modules filename. Patch written by Amaury Forgeot
|
||||||
d'Arc.
|
d'Arc.
|
||||||
|
|
||||||
- Issue #9011: Remove buggy and unnecessary (in 3.x) ST->AST
|
|
||||||
compilation code dealing with unary minus applied to a constant.
|
|
||||||
The removed code was mutating the ST, causing a second compilation
|
|
||||||
to fail.
|
|
||||||
|
|
||||||
- Issue #9058: Remove assertions about INT_MAX in UnicodeDecodeError.
|
- Issue #9058: Remove assertions about INT_MAX in UnicodeDecodeError.
|
||||||
|
|
||||||
- Issue #8941: decoding big endian UTF-32 data in UCS-2 builds could crash
|
- Issue #8941: decoding big endian UTF-32 data in UCS-2 builds could crash
|
||||||
|
|
26
Python/ast.c
26
Python/ast.c
|
@ -1664,8 +1664,34 @@ ast_for_trailer(struct compiling *c, const node *n, expr_ty left_expr)
|
||||||
static expr_ty
|
static expr_ty
|
||||||
ast_for_factor(struct compiling *c, const node *n)
|
ast_for_factor(struct compiling *c, const node *n)
|
||||||
{
|
{
|
||||||
|
node *pfactor, *ppower, *patom, *pnum;
|
||||||
expr_ty expression;
|
expr_ty expression;
|
||||||
|
|
||||||
|
/* If the unary - operator is applied to a constant, don't generate
|
||||||
|
a UNARY_NEGATIVE opcode. Just store the approriate value as a
|
||||||
|
constant. The peephole optimizer already does something like
|
||||||
|
this but it doesn't handle the case where the constant is
|
||||||
|
(sys.maxint - 1). In that case, we want a PyIntObject, not a
|
||||||
|
PyLongObject.
|
||||||
|
*/
|
||||||
|
if (TYPE(CHILD(n, 0)) == MINUS
|
||||||
|
&& NCH(n) == 2
|
||||||
|
&& TYPE((pfactor = CHILD(n, 1))) == factor
|
||||||
|
&& NCH(pfactor) == 1
|
||||||
|
&& TYPE((ppower = CHILD(pfactor, 0))) == power
|
||||||
|
&& NCH(ppower) == 1
|
||||||
|
&& TYPE((patom = CHILD(ppower, 0))) == atom
|
||||||
|
&& TYPE((pnum = CHILD(patom, 0))) == NUMBER) {
|
||||||
|
char *s = PyObject_MALLOC(strlen(STR(pnum)) + 2);
|
||||||
|
if (s == NULL)
|
||||||
|
return NULL;
|
||||||
|
s[0] = '-';
|
||||||
|
strcpy(s + 1, STR(pnum));
|
||||||
|
PyObject_FREE(STR(pnum));
|
||||||
|
STR(pnum) = s;
|
||||||
|
return ast_for_atom(c, patom);
|
||||||
|
}
|
||||||
|
|
||||||
expression = ast_for_expr(c, CHILD(n, 1));
|
expression = ast_for_expr(c, CHILD(n, 1));
|
||||||
if (!expression)
|
if (!expression)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue