8000 gh-135148: Correctly handle f/t strings with comments and debug expressions by pablogsal · Pull Request #135198 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-135148: Correctly handle f/t strings with comments and debug expressions #135198

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

Merged
merged 4 commits into from
Jul 16, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix linting
  • Loading branch information
pablogsal committed Jun 7, 2025
commit 3c86cce55143ed98db6c8a51a431a363eecbd4aa
10 changes: 5 additions & 5 deletions Parser/lexer/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ set_ftstring_expr(struct tok_state* tok, struct token *token, char c) {
int in_string = 0;
char quote_char = 0;
char string_quote = 0;

for (Py_ssize_t i = 0; i < tok_mode->last_expr_size - tok_mode->last_expr_end; i++) {
char ch = tok_mode->last_expr_buffer[i];

// Skip escaped characters
if (ch == '\\') {
i++;
continue;
}

// Handle quotes
if (ch == '"' || ch == '\'') {
if (!in_string) {
Expand All @@ -147,7 +147,7 @@ set_ftstring_expr(struct tok_state* tok, struct token *token, char c) {
}
continue;
}

// Check for # outside strings
if (ch == '#' && !in_string) {
hash_detected = 1;
Expand Down Expand Up @@ -183,7 +183,7 @@ set_ftstring_expr(struct tok_state* tok, struct token *token, char c) {
}
// Skip comments
else if (ch == '#' && !in_string) {
while (i < tok_mode->last_expr_size - tok_mode->last_expr_end &&
while (i < tok_mode->last_expr_size - tok_mode->last_expr_end &&
tok_mode->last_expr_buffer[i] != '\n') {
i++;
}
Expand Down
Loading
0