8000 simplify things and add test · python/cpython@3f86aa3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f86aa3

Browse files
committed
simplify things and add test
1 parent 13f4e21 commit 3f86aa3

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

Lib/test/test_fstring.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,14 @@ def __repr__(self):
16491649
#self.assertEqual(f'X{x =}Y', 'Xx\t='+repr(x)+'Y')
16501650
#self.assertEqual(f'X{x = }Y', 'Xx\t=\t'+repr(x)+'Y')
16511651

1652+
def test_debug_expressions_are_raw_strings(self):
1653+
1654+
self.assertEqual(f'{b"\N{OX}"=}', 'b"\\N{OX}"=b\'\\\\N{OX}\'')
1655+
self.assertEqual(f'{r"\xff"=}', 'r"\\xff"=\'\\\\xff\'')
1656+
self.assertEqual(f'{r"\n"=}', 'r"\\n"=\'\\\\n\'')
1657+
self.assertEqual(f"{'\''=}", "'\\''=\"'\"")
1658+
self.assertEqual(f'{'\xc5'=}', r"'\xc5'='Å'")
1659+
16521660
def test_walrus(self):
16531661
x = 20
16541662
# This isn't an assignment expression, it's 'x', with a format

Parser/action_helpers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,7 @@ _PyPegen_nonparen_genexp_in_call(Parser *p, expr_ty args, asdl_comprehension_seq
12481248

12491249
static expr_ty
12501250
_PyPegen_decode_fstring_part(Parser* p, int is_raw, expr_ty constant, Token* token) {
1251+
12511252
assert(PyUnicode_CheckExact(constant->v.Constant.value));
12521253
const char* bstr = PyUnicode_AsUTF8(constant->v.Constant.value);
12531254
if (bstr == NULL) {

Parser/lexer/lexer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ set_fstring_expr(struct tok_state* tok, struct token *token, char c) {
153153
}
154154< 8874 /td>

155155
result[j] = '\0'; // Null-terminate the result string
156-
res = PyUnicode_DecodeUTF8Stateful(result, j, NULL, NULL);
156+
res = PyUnicode_DecodeUTF8(result, j, NULL);
157157
PyMem_Free(result);
158158
} else {
159-
res = PyUnicode_DecodeUTF8Stateful(
159+
res = PyUnicode_DecodeUTF8(
160160
tok_mode->last_expr_buffer,
161161
tok_mode->last_expr_size - tok_mode->last_expr_end,
162-
NULL, NULL
162+
NULL
163163
);
164164

165165
}

0 commit comments

Comments
 (0)
0