Skip to content
Closed
Show file tree
Hide file tree
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
Accept only one string, make it a raw bytes
  • Loading branch information
gvanrossum committed May 3, 2022
commit 12ced2c289c02a093ac3c932b3df911eb5ab4f74
2 changes: 1 addition & 1 deletion Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ slice[expr_ty]:
| a=named_expression { a }

atom[expr_ty]:
| a=NAME &STRING b=strings { _PyPegen_tag_string(p, a, b) }
| a=NAME b=STRING { _PyPegen_tag_string(p, a, b) }
| NAME
| 'True' { _PyAST_Constant(Py_True, NULL, EXTRA) }
| 'False' { _PyAST_Constant(Py_False, NULL, EXTRA) }
Expand Down
5 changes: 4 additions & 1 deletion Parser/action_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,14 @@ _PyPegen_seq_delete_starred_exprs(Parser *p, asdl_seq *kwargs)
}

expr_ty
_PyPegen_tag_string(Parser *p, expr_ty tag, expr_ty str)
_PyPegen_tag_string(Parser *p, expr_ty tag, Token *t)
{
// No prefixes (f, r, b, u)
// Parse like fstring
// Create a node similar to f-string AST
expr_ty str = _PyAST_Constant(t->bytes, NULL, t->lineno,
t->col_offset, t->end_lineno,
t->end_col_offset, p->arena);
return _PyAST_TagString(tag, str,
tag->lineno, tag->col_offset, str->end_lineno, str->end_col_offset,
p->arena);
Expand Down
14 changes: 6 additions & 8 deletions Parser/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Parser/pegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ expr_ty _PyPegen_collect_call_seqs(Parser *, asdl_expr_seq *, asdl_seq *,
int lineno, int col_offset, int end_lineno,
int end_col_offset, PyArena *arena);
expr_ty _PyPegen_concatenate_strings(Parser *p, asdl_seq *);
expr_ty _PyPegen_tag_string(Parser *p, expr_ty, expr_ty);
expr_ty _PyPegen_tag_string(Parser *p, expr_ty, Token *);
expr_ty _PyPegen_ensure_imaginary(Parser *p, expr_ty);
expr_ty _PyPegen_ensure_real(Parser *p, expr_ty);
asdl_seq *_PyPegen_join_sequences(Parser *, asdl_seq *, asdl_seq *);
Expand Down
2 changes: 1 addition & 1 deletion Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -4918,7 +4918,7 @@ compiler_tag_string(struct compiler *c, expr_ty e)
if (str->kind == Constant_kind) {
PyObject *value = str->v.Constant.value;
PyObject *kind = str->v.Constant.kind;
if (kind == NULL && PyUnicode_CheckExact(value)) {
if (kind == NULL && PyBytes_CheckExact(value)) {
// Generate code for tag(value)
asdl_expr_seq *args =
_Py_asdl_expr_seq_new(1, c->c_arena);
Expand Down