diff options
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/Python/compile.c b/Python/compile.c index 86f2a09ffb..dd27ba840f 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3946,8 +3946,8 @@ compiler_formatted_value(struct compiler *c, expr_ty e) /* Our oparg encodes 2 pieces of information: the conversion character, and whether or not a format_spec was provided. - Convert the conversion char to 2 bits: - None: 000 0x0 FVC_NONE + Convert the conversion char to 3 bits: + : 000 0x0 FVC_NONE The default if nothing specified. !s : 001 0x1 FVC_STR !r : 010 0x2 FVC_REPR !a : 011 0x3 FVC_ASCII @@ -3957,19 +3957,26 @@ compiler_formatted_value(struct compiler *c, expr_ty e) no : 000 0x0 */ + int conversion = e->v.FormattedValue.conversion; int oparg; - /* Evaluate the expression to be formatted. */ + if (e->v.FormattedValue.expr_text) { + /* Push the text of the expression (which already has the '=' in + it. */ + ADDOP_LOAD_CONST(c, e->v.FormattedValue.expr_text); + } + + /* The expression to be formatted. */ VISIT(c, expr, e->v.FormattedValue.value); - switch (e->v.FormattedValue.conversion) { + switch (conversion) { case 's': oparg = FVC_STR; break; case 'r': oparg = FVC_REPR; break; case 'a': oparg = FVC_ASCII; break; case -1: oparg = FVC_NONE; break; default: - PyErr_SetString(PyExc_SystemError, - "Unrecognized conversion character"); + PyErr_Format(PyExc_SystemError, + "Unrecognized conversion character %d", conversion); return 0; } if (e->v.FormattedValue.format_spec) { @@ -3980,6 +3987,12 @@ compiler_formatted_value(struct compiler *c, expr_ty e) /* And push our opcode and oparg */ ADDOP_I(c, FORMAT_VALUE, oparg); + + /* If we have expr_text, join the 2 strings on the stack. */ + if (e->v.FormattedValue.expr_text) { + ADDOP_I(c, BUILD_STRING, 2); + } + return 1; } |