Skip to content

Conversation

@lysnikolaou
Copy link
Member

@lysnikolaou lysnikolaou commented Jun 23, 2020

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
Copy link
Member Author

lysnikolaou commented Jun 23, 2020

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
Copy link
Member

@ericvsmith ericvsmith left a comment

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.

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
Copy link
Member

@pablogsal pablogsal Jun 23, 2020

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

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