Skip to content

Commit f0e3423

Browse files
committed
fixup! gh-137314: Fix incorrect treatment of format specs in raw fstrings (GH-137328) (cherry picked from commit 0153d82)
1 parent 0db3d08 commit f0e3423

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

Parser/action_helpers.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <Python.h>
22

33
#include "pegen.h"
4+
#include "lexer/state.h"
45
#include "string_parser.h"
56
#include "pycore_runtime.h" // _PyRuntime
67
#include "pycore_pystate.h" // _PyInterpreterState_GET()
@@ -1374,7 +1375,7 @@ expr_ty _PyPegen_decoded_constant_from_token(Parser* p, Token* tok) {
13741375
int is_raw = 0;
13751376
if (INSIDE_FSTRING(p->tok)) {
13761377
tokenizer_mode *mode = TOK_GET_MODE(p->tok);
1377-
is_raw = mode->raw;
1378+
is_raw = mode->f_string_raw;
13781379
}
13791380

13801381
PyObject* str = _PyPegen_decode_string(p, is_raw, bstr, bsize, tok);

Parser/lexer/lexer.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,6 @@
2222
|| c == '_'\
2323
|| (c >= 128))
2424

25-
#ifdef Py_DEBUG
26-
static inline tokenizer_mode* TOK_GET_MODE(struct tok_state* tok) {
27-
assert(tok->tok_mode_stack_index >= 0);
28-
assert(tok->tok_mode_stack_index < MAXFSTRINGLEVEL);
29-
return &(tok->tok_mode_stack[tok->tok_mode_stack_index]);
30-
}
31-
static inline tokenizer_mode* TOK_NEXT_MODE(struct tok_state* tok) {
32-
assert(tok->tok_mode_stack_index >= 0);
33-
assert(tok->tok_mode_stack_index + 1 < MAXFSTRINGLEVEL);
34-
return &(tok->tok_mode_stack[++tok->tok_mode_stack_index]);
35-
}
36-
#else
37-
#define TOK_GET_MODE(tok) (&(tok->tok_mode_stack[tok->tok_mode_stack_index]))
38-
#define TOK_NEXT_MODE(tok) (&(tok->tok_mode_stack[++tok->tok_mode_stack_index]))
39-
#endif
40-
4125
#define MAKE_TOKEN(token_type) _PyLexer_token_setup(tok, token, token_type, p_start, p_end)
4226
#define MAKE_TYPE_COMMENT_TOKEN(token_type, col_offset, end_col_offset) (\
4327
_PyLexer_type_comment_token_setup(tok, token, token_type, col_offset, end_col_offset, p_start, p_end))

Parser/lexer/state.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef _PY_LEXER_H_
22
#define _PY_LEXER_H_
33

4+
#include "Python.h"
45
#include "object.h"
56

67
#define MAXINDENT 100 /* Max indentation level */
@@ -138,5 +139,20 @@ void _PyTokenizer_Free(struct tok_state *);
138139
void _PyToken_Free(struct token *);
139140
void _PyToken_Init(struct token *);
140141

142+
#ifdef Py_DEBUG
143+
static inline tokenizer_mode* TOK_GET_MODE(struct tok_state* tok) {
144+
assert(tok->tok_mode_stack_index >= 0);
145+
assert(tok->tok_mode_stack_index < MAXFSTRINGLEVEL);
146+
return &(tok->tok_mode_stack[tok->tok_mode_stack_index]);
147+
}
148+
static inline tokenizer_mode* TOK_NEXT_MODE(struct tok_state* tok) {
149+
assert(tok->tok_mode_stack_index >= 0);
150+
assert(tok->tok_mode_stack_index + 1 < MAXFSTRINGLEVEL);
151+
return &(tok->tok_mode_stack[++tok->tok_mode_stack_index]);
152+
}
153+
#else
154+
#define TOK_GET_MODE(tok) (&(tok->tok_mode_stack[tok->tok_mode_stack_index]))
155+
#define TOK_NEXT_MODE(tok) (&(tok->tok_mode_stack[++tok->tok_mode_stack_index]))
156+
#endif
141157

142158
#endif

0 commit comments

Comments
 (0)