Skip to content

Commit 03af022

Browse files
Support class scoped variable lookup in interpolation lambdas (take 2) (python#45)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
1 parent 62c9e0a commit 03af022

14 files changed

+94
-48
lines changed

Include/internal/pycore_ast.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_ast_state.h

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct _Py_global_strings {
3030
struct {
3131
STRUCT_FOR_STR(anon_dictcomp, "<dictcomp>")
3232
STRUCT_FOR_STR(anon_genexpr, "<genexpr>")
33+
STRUCT_FOR_STR(anon_interpolation, "<interpolation>")
3334
STRUCT_FOR_STR(anon_lambda, "<lambda>")
3435
STRUCT_FOR_STR(anon_listcomp, "<listcomp>")
3536
STRUCT_FOR_STR(anon_module, "<module>")
@@ -493,6 +494,7 @@ struct _Py_global_strings {
493494
STRUCT_FOR_ID(insert_pis)
494495
STRUCT_FOR_ID(instructions)
495496
STRUCT_FOR_ID(intern)
497+
STRUCT_FOR_ID(interpolation)
496498
STRUCT_FOR_ID(intersection)
497499
STRUCT_FOR_ID(interval)
498500
STRUCT_FOR_ID(is_running)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/decodedobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ DecodedConcrete_repr(PyObject *s)
7070
{
7171
PyObject *left = NULL, *repr = NULL, *right = NULL, *leftrepr = NULL;
7272
PyObject *final = NULL;
73-
73+
7474
left = PyUnicode_FromString("DecodedConcrete(");
7575
if (left == NULL) {
7676
goto exit;

Parser/Python.asdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module Python
8080
| FormattedValue(expr value, int conversion, expr? format_spec)
8181
| JoinedStr(expr* values)
8282
| TagString(expr tag, expr str)
83-
| Interpolation(expr lambda, expr str, expr? conversion, expr? format_spec)
83+
| Interpolation(expr body, expr str, expr? conversion, expr? format_spec)
8484
| Decoded(constant value, string? kind)
8585
| Constant(constant value, string? kind)
8686

Parser/action_helpers.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,17 +1412,6 @@ _PyPegen_name_from_f_string_start(Parser *p, Token* t)
14121412
t->end_col_offset, p->arena);
14131413
}
14141414

1415-
static expr_ty
1416-
lambdafy(Parser *p, expr_ty arg)
1417-
{
1418-
arguments_ty args = _PyPegen_empty_arguments(p);
1419-
if (args == NULL)
1420-
return NULL;
1421-
return _PyAST_Lambda(args, arg,
1422-
arg->lineno, arg->col_offset, arg->end_lineno, arg->end_col_offset,
1423-
p->arena);
1424-
}
1425-
14261415
expr_ty
14271416
_PyPegen_tag_str(Parser *p, Token* a, asdl_expr_seq* raw_expressions, Token*b) {
14281417
expr_ty tag = _PyPegen_name_from_f_string_start(p, a);
@@ -1441,10 +1430,6 @@ _PyPegen_tag_str(Parser *p, Token* a, asdl_expr_seq* raw_expressions, Token*b) {
14411430
if (value->kind == FormattedValue_kind) {
14421431

14431432
expr_ty expr = value->v.FormattedValue.value;
1444-
expr_ty lambda = lambdafy(p, expr);
1445-
if (lambda == NULL) {
1446-
return NULL;
1447-
}
14481433

14491434
constant rawstr = _PyAST_ExprAsUnicode(expr);
14501435
if (rawstr == NULL) {
@@ -1475,7 +1460,7 @@ _PyPegen_tag_str(Parser *p, Token* a, asdl_expr_seq* raw_expressions, Token*b) {
14751460
}
14761461

14771462
expr_ty spec = value->v.FormattedValue.format_spec;
1478-
expr_ty interpolation = _PyAST_Interpolation(lambda,
1463+
expr_ty interpolation = _PyAST_Interpolation(expr,
14791464
raw, conv, spec,
14801465
value->lineno, value->col_offset,
14811466
value->end_lineno, value->end_col_offset,
@@ -1604,7 +1589,6 @@ expr_ty _PyPegen_formatted_value(Parser *p, expr_ty expression, Token *debug, in
16041589
debug_metadata = closing_brace->metadata;
16051590
}
16061591

1607-
16081592
expr_ty debug_text;
16091593
if (debug_as_decoded_ast) {
16101594
debug_text = _PyAST_Decoded(debug_metadata, NULL, lineno, col_offset + 1, debug_end_line,

Python/Python-ast.c

Lines changed: 18 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)