Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

ericvsmith
Copy link
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
@@ -290,6 +284,15 @@ def test_annotations(self):
eq("(x:=10)")
eq("f'{(x:=10):=10}'")

# f-strings with '=' don't round trip very well, so set the expected
Copy link
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.


*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
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

*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
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. */

expr_text_end = *str;

/* Set *expr_text to the text of the expression. */
*expr_text = PyUnicode_FromStringAndSize(expr_start, *str-expr_start);
Copy link
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.

/* We have a literal, concatenate it. */
assert(PyUnicode_GET_LENGTH(literal[i]) != 0);
if (FstringParser_ConcatAndDel(state, literal[i]) < 0)
return -1;
Copy link
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
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