Skip to content

bpo-41084: Adjust message when an f-string expression causes a SyntaxError#21084

Merged
pablogsal merged 5 commits into
python:masterfrom
lysnikolaou:fstring-error-message
Jun 26, 2020
Merged

bpo-41084: Adjust message when an f-string expression causes a SyntaxError#21084
pablogsal merged 5 commits into
python:masterfrom
lysnikolaou:fstring-error-message

Conversation

@lysnikolaou

@lysnikolaou lysnikolaou commented Jun 23, 2020

Copy link
Copy Markdown
Member

Prefix the error message with f-string: , when parsing an f-string
expression which throws a SyntaxError.

https://bugs.python.org/issue41084

…Error

Prefix the error message with `fstring: `, when parsing an f-string
expression throws a `SyntaxError`.
@lysnikolaou

lysnikolaou commented Jun 23, 2020

Copy link
Copy Markdown
Member Author

Wow, bpo-41084 and GH-21084. 4/5 same digits is as close as it gets at the moment, I guess.

@lysnikolaou
lysnikolaou force-pushed the fstring-error-message branch from b8ecf05 to 2367cdc Compare June 23, 2020 16:49

@ericvsmith ericvsmith left a comment

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.

The changes look good to me.

Comment thread Parser/pegen.c
const char *fstring_msg = "f-string: ";
Py_ssize_t len = strlen(fstring_msg) + strlen(errmsg);

char *new_errmsg = PyMem_RawMalloc(len + 1); // Lengths of both strings plus NULL character

@pablogsal pablogsal Jun 23, 2020

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.

This should be PyMem_Malloc no? Any reason why you need the raw allocator?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I used PyMem_RawMalloc, because fstring_compile_expr uses it for str in string_parser.c. You know best what's more suitable here.

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 would like to move them to PyMem_Malloc, but let's do that in a different PR

@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @lysnikolaou for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

@bedevere-bot

Copy link
Copy Markdown

GH-21188 is a backport of this pull request to the 3.9 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 27, 2020
…Error (pythonGH-21084)

Prefix the error message with `fstring: `, when parsing an f-string expression throws a `SyntaxError`.
(cherry picked from commit 2e0a920)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
miss-islington added a commit that referenced this pull request Jun 27, 2020
…Error (GH-21084)

Prefix the error message with `fstring: `, when parsing an f-string expression throws a `SyntaxError`.
(cherry picked from commit 2e0a920)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
@bedevere-bot

This comment has been minimized.

fasih pushed a commit to fasih/cpython that referenced this pull request Jun 29, 2020
…Error (pythonGH-21084)

Prefix the error message with `fstring: `, when parsing an f-string expression throws a `SyntaxError`.
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.

6 participants