Skip to content

bpo-37050: Remove expr_text from FormattedValue ast node, use Constant node instead#13597

Merged
ericvsmith merged 7 commits intopython:masterfrom
ericvsmith:remove-expr_text-from-FormattedValue-ast-node
May 27, 2019
Merged

bpo-37050: Remove expr_text from FormattedValue ast node, use Constant node instead#13597
ericvsmith merged 7 commits intopython:masterfrom
ericvsmith:remove-expr_text-from-FormattedValue-ast-node

Conversation

@ericvsmith
Copy link
Copy Markdown
Member

@ericvsmith ericvsmith commented May 27, 2019

@ericvsmith ericvsmith merged commit 6f6ff8a into python:master May 27, 2019
@ericvsmith ericvsmith deleted the remove-expr_text-from-FormattedValue-ast-node branch May 27, 2019 19:32
Comment thread Lib/test/test_future.py
eq("(x:=10)")
eq("f'{(x:=10):=10}'")

# f-strings with '=' don't round trip very well, so set the expected
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is worth to move this into separate method. It can even be decorated as cpython_only. I think that if an alternate implementation is smart enough to roundtrip these case, it is still a valid Python implementation.

Comment thread Python/ast.c

*expression is set to the expression. For an '=' "debug" expression,
*expr_text is set to the debug text (the original text of the expression,
*including the '=' and any whitespace around it, as a string object). If
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*including the '=' and any whitespace around it, as a string object). If
including the '=' and any whitespace around it, as a string object). If

Comment thread Python/ast.c
*expression is set to the expression. For an '=' "debug" expression,
*expr_text is set to the debug text (the original text of the expression,
*including the '=' and any whitespace around it, as a string object). If
*not a debug expression, *expr_text set to NULL. */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*not a debug expression, *expr_text set to NULL. */
not a debug expression, *expr_text set to NULL. */

Comment thread Python/ast.c
expr_text_end = *str;

/* Set *expr_text to the text of the expression. */
*expr_text = PyUnicode_FromStringAndSize(expr_start, *str-expr_start);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that *expr_text can be leaked at the error label.

Comment thread Python/ast.c
/* We have a literal, concatenate it. */
assert(PyUnicode_GET_LENGTH(literal[i]) != 0);
if (FstringParser_ConcatAndDel(state, literal[i]) < 0)
return -1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

literal[1] can be leaked here.

@ericvsmith
Copy link
Copy Markdown
Member Author

Thanks, Serhiy. I was in a rush to get this change in for B1. I'll address these in a subsequent commit.

DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
…t node instead (pythonGH-13597)

When using the "=" debug functionality of f-strings, use another Constant node (or a merged constant node) instead of adding expr_text to the FormattedValue node.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants