Skip to content

Commit d62481f

Browse files
committed
Disable comp_inlined in symbol table to match compiler
The compiler does not yet implement PEP 709 inlined comprehensions (is_inlined_comprehension_context always returns false), but the symbol table was marking comprehensions as inlined. This mismatch could cause comprehension-local symbols to be merged into the parent scope while the compiler still looks them up in a separate scope.
1 parent 2282a51 commit d62481f

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

Lib/test/test_symtable.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,6 @@ def get_identifiers_recursive(self, st, res):
561561
for ch in st.get_children():
562562
self.get_identifiers_recursive(ch, res)
563563

564-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 2 != 1
565564
def test_loopvar_in_only_one_scope(self):
566565
# ensure that the loop variable appears only once in the symtable
567566
comps = [

crates/codegen/src/symboltable.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,20 +2037,13 @@ impl SymbolTableBuilder {
20372037
self.line_index_start(range),
20382038
);
20392039

2040-
// Mark non-generator comprehensions as inlined (PEP 709)
2041-
// inline_comp = entry->ste_comprehension && !entry->ste_generator && !ste->ste_can_see_class_scope
2042-
// We check is_generator and can_see_class_scope of parent
2043-
let parent_can_see_class = self
2044-
.tables
2045-
.get(self.tables.len().saturating_sub(2))
2046-
.map(|t| t.can_see_class_scope)
2047-
.unwrap_or(false);
2048-
if !is_generator
2049-
&& !parent_can_see_class
2050-
&& let Some(table) = self.tables.last_mut()
2051-
{
2052-
table.comp_inlined = true;
2053-
}
2040+
// PEP 709: inlined comprehensions are not yet implemented in the
2041+
// compiler (is_inlined_comprehension_context always returns false),
2042+
// so do NOT mark comp_inlined here. Setting it would cause the
2043+
// symbol-table analyzer to merge comprehension-local symbols into
2044+
// the parent scope, while the compiler still emits a separate code
2045+
// object — leading to the merged symbols being missing from the
2046+
// comprehension's own symbol table lookup.
20542047

20552048
// Register the passed argument to the generator function as the name ".0"
20562049
self.register_name(".0", SymbolUsage::Parameter, range)?;

0 commit comments

Comments
 (0)