mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.13] gh-137314: Fix incorrect treatment of format specs in raw fstrings (GH-137328) (#137345)
gh-137314: Fix incorrect treatment of format specs in raw fstrings (GH-137328)
(cherry picked from commit 0153d82a5a)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
parent
7adea430c1
commit
23a3e892ee
5 changed files with 59 additions and 17 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include <Python.h>
|
||||
|
||||
#include "pegen.h"
|
||||
#include "lexer/state.h"
|
||||
#include "string_parser.h"
|
||||
#include "pycore_runtime.h" // _PyRuntime
|
||||
#include "pycore_pystate.h" // _PyInterpreterState_GET()
|
||||
|
|
@ -1369,7 +1370,15 @@ expr_ty _PyPegen_decoded_constant_from_token(Parser* p, Token* tok) {
|
|||
if (PyBytes_AsStringAndSize(tok->bytes, &bstr, &bsize) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
PyObject* str = _PyPegen_decode_string(p, 0, bstr, bsize, tok);
|
||||
|
||||
// Check if we're inside a raw f-string for format spec decoding
|
||||
int is_raw = 0;
|
||||
if (INSIDE_FSTRING(p->tok)) {
|
||||
tokenizer_mode *mode = TOK_GET_MODE(p->tok);
|
||||
is_raw = mode->f_string_raw;
|
||||
}
|
||||
|
||||
PyObject* str = _PyPegen_decode_string(p, is_raw, bstr, bsize, tok);
|
||||
if (str == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue