Skip to content

Commit ac9be9f

Browse files
authored
Merge pull request RustPython#4351 from yt2b/fix_pysymbol
make `test_local` pass
2 parents c01f014 + 59c6c6f commit ac9be9f

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

Lib/test/test_symtable.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ def test_nonlocal(self):
128128
expected = ("some_var",)
129129
self.assertEqual(self.other_internal.get_nonlocals(), expected)
130130

131-
# TODO: RUSTPYTHON
132-
@unittest.expectedFailure
133131
def test_local(self):
134132
self.assertTrue(self.spam.lookup("x").is_local())
135133
self.assertFalse(self.spam.lookup("bar").is_local())

compiler/codegen/src/symboltable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl Symbol {
150150
}
151151

152152
pub fn is_local(&self) -> bool {
153-
self.scope == SymbolScope::Local
153+
matches!(self.scope, SymbolScope::Local | SymbolScope::Cell)
154154
}
155155

156156
pub fn is_bound(&self) -> bool {

vm/src/stdlib/symtable.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ mod symtable {
8989
.filter(|table| table.name == name)
9090
.cloned()
9191
.collect(),
92+
is_top_scope: self.symtable.name == "top",
9293
}
9394
.into_ref(vm))
9495
} else {
@@ -123,6 +124,7 @@ mod symtable {
123124
.filter(|&table| table.name == s.name)
124125
.cloned()
125126
.collect(),
127+
is_top_scope: self.symtable.name == "top",
126128
})
127129
.into_ref(vm)
128130
.into()
@@ -154,6 +156,7 @@ mod symtable {
154156
struct PySymbol {
155157
symbol: Symbol,
156158
namespaces: Vec<SymbolTable>,
159+
is_top_scope: bool,
157160
}
158161

159162
impl fmt::Debug for PySymbol {
@@ -176,7 +179,7 @@ mod symtable {
176179

177180
#[pymethod]
178181
fn is_local(&self) -> bool {
179-
self.symbol.is_local()
182+
self.symbol.is_local() || (self.is_top_scope && self.symbol.is_bound())
180183
}
181184

182185
#[pymethod]

0 commit comments

Comments
 (0)