FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-124697: Represent inlined comprehensions as subscopes in the symbol table by iritkatriel · Pull Request #156819 · python/cpython · GitHub

Repository navigation

Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3245fd7
gh-124697: Represent inlined comprehensions as subscopes in the symbo…
iritkatriel Aug 26, 2026
8dfe966
gh-124697: Add NEWS entry for inlined comprehension symbol tables
iritkatriel Sep 2, 2026
97ace7d
gh-124697: Add What's New entry for inlined comprehension symbol tables
iritkatriel Sep 2, 2026
21ab5dd
simpligy logic and edit docs
iritkatriel Sep 2, 2026
045913c
redundant check
iritkatriel Sep 2, 2026
0c2ad7e
rename helper and use it in more places
iritkatriel Sep 2, 2026
a459371
Merge branch 'main' into subscope
iritkatriel Sep 2, 2026
3f7b483
finalize nested against enclosing listcomp
iritkatriel Sep 3, 2026
9d9ebfc
do not splice
iritkatriel Sep 3, 2026
bee5d57
fix error handling in push/pop_inlined_comprehension_state
iritkatriel Sep 3, 2026
0a13f59
do not remove free variables from comprehension scope
iritkatriel Sep 3, 2026
28c532b
Merge branch 'main' into subscope
iritkatriel Sep 3, 2026
f4ad426
fix test
iritkatriel Sep 3, 2026
ef2a6da
fix stale comment
iritkatriel Sep 3, 2026
8b37711
make the symtable honest about __class__ etc
iritkatriel Sep 3, 2026
ce7433e
no more climbing in _PyST_GetSymbol - symbol table is honest now
iritkatriel Sep 3, 2026
48f9865
Merge branch 'main' into subscope
iritkatriel Sep 3, 2026
3515cc0
remove DEF_COMP_CELL
iritkatriel Sep 3, 2026
ea23c17
deduplicate frame locals
iritkatriel Sep 4, 2026
045091d
Merge branch 'main' into subscope
iritkatriel Sep 10, 2026
5216591
add test
iritkatriel Sep 12, 2026
e6e9133
another test
iritkatriel Sep 12, 2026
4238c3a
Merge branch 'main' into subscope
iritkatriel Sep 17, 2026
5661919
do not pop block in case of error
iritkatriel Sep 17, 2026
90b6e28
dedup keys(), values(), items(), and len() on frame
iritkatriel Sep 17, 2026
7c2656e
is_free_in_any_child checks children of nested comprehensions
iritkatriel Sep 17, 2026
98509f0
versionadded
iritkatriel Sep 17, 2026
2918e2c
handle symbols which do not exist in an inlined comprehension's symta…
iritkatriel Sep 17, 2026
2c96ad6
finalize inlined comp before analyze_cells
iritkatriel Sep 17, 2026
3e173e3
add doc
iritkatriel Sep 18, 2026
436861a
propagate USED flag from inlined comp to enclosing scope
iritkatriel Sep 18, 2026
f99d475
add whatsnew info
iritkatriel Sep 18, 2026
9f2c07d
Merge branch 'main' into subscope
iritkatriel Sep 21, 2026
ed24ee4
more tests
iritkatriel Sep 21, 2026
6bb04f1
Merge branch 'main' into subscope
iritkatriel Sep 21, 2026
c05d147
doc tweak
iritkatriel Sep 21, 2026
39b65fc
avoid use-after-free
iritkatriel Sep 21, 2026
4ad011f
Merge branch 'main' into subscope
iritkatriel Sep 22, 2026
4c0bfd1
test needs socket
iritkatriel Sep 22, 2026
be7f556
Merge branch 'main' into subscope
iritkatriel Sep 22, 2026
b61c46f
Merge branch 'main' into subscope
iritkatriel Sep 22, 2026
File filter

Filter by extension

Filter by extension .c  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
rename helper and use it in more places
  • Loading branch information
iritkatriel committed Sep 2, 2026
commit 0c2ad7e1c6df3549ecb10ca30f13701ada17ec9b
25 changes: 11 additions & 14 deletions Python/symtable.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@

#define IS_ASYNC_DEF(st) ((st)->st_cur->ste_type == FunctionBlock && (st)->st_cur->ste_coroutine)

static int
ste_uses_fast_locals(PySTEntryObject *ste)
{
return _PyST_IsFunctionLike(ste) || ste->ste_type == InlinedComprehensionBlock;
}

static PySTEntryObject *
ste_new(struct symtable *st, identifier name, _Py_block_ty block,
void *key, _Py_SourceLocation loc)
Expand Down Expand Up @@ -130,8 +136,7 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,

if (st->st_cur != NULL &&
(st->st_cur->ste_nested ||
_PyST_IsFunctionLike(st->st_cur) ||
st->st_cur->ste_type == InlinedComprehensionBlock))
ste_uses_fast_locals(st->st_cur)))
ste->ste_nested = 1;
ste->ste_generator = 0;
ste->ste_coroutine = 0;
Expand Down Expand Up @@ -582,13 +587,6 @@ _PyST_IsFunctionLike(PySTEntryObject *ste)
|| ste->ste_type == TypeParametersBlock;
}

/* True if this block binds locals that are visible to nested scopes */
static int
ste_binds_locals_for_children(PySTEntryObject *ste)
{
return _PyST_IsFunctionLike(ste) || ste->ste_type == InlinedComprehensionBlock;
}

static int
error_at_directive(PySTEntryObject *ste, PyObject *name)
{
Expand Down Expand Up @@ -1321,7 +1319,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
/* Populate global and bound sets to be passed to children. */
if (ste->ste_type != ClassBlock) {
/* Add function locals to bound set */
if (ste_binds_locals_for_children(ste)) {
if (ste_uses_fast_locals(ste)) {
temp = PyNumber_InPlaceOr(newbound, local);
if (!temp)
goto error;
Expand Down Expand Up @@ -1409,7 +1407,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
}

/* Check if any local variables must be converted to cell variables */
if (ste_binds_locals_for_children(ste) && !analyze_cells(scopes, newfree, inlined_cells)) {
if (ste_uses_fast_locals(ste) && !analyze_cells(scopes, newfree, inlined_cells)) {
goto error;
}
else if (ste->ste_type == ClassBlock && !drop_class_free(ste, newfree)) {
Expand Down Expand Up @@ -2690,7 +2688,7 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
return 0;
}
if (!allows_top_level_await(st)) {
if (!ste_binds_locals_for_children(st->st_cur)) {
if (!ste_uses_fast_locals(st->st_cur)) {
PyErr_SetString(PyExc_SyntaxError,
"'await' outside function");
SET_ERROR_LOCATION(st->st_filename, LOCATION(e));
Expand Down Expand Up @@ -2768,8 +2766,7 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
}
/* Special-case super: it counts as a use of __class__ */
if (e->v.Name.ctx == Load &&
(_PyST_IsFunctionLike(st->st_cur) ||
st->st_cur->ste_type == InlinedComprehensionBlock) &&
ste_uses_fast_locals(st->st_cur) &&
_PyUnicode_EqualToASCIIString(e->v.Name.id, "super")) {
if (!symtable_add_def(st, &_Py_ID(__class__), USE, LOCATION(e)))
return 0;
Expand Down
Loading

Back | FazBrowse Home | New Git URL