Skip to content

Commit 38a8007

Browse files
authored
Merge pull request RustPython#4355 from yt2b/fix_pysymbol
make `test_globals` pass
2 parents 9acfef8 + f3eb952 commit 38a8007

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Lib/test/test_symtable.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ def test_function_info(self):
106106
self.assertEqual(sorted(func.get_globals()), ["bar", "glob", "some_assigned_global_var"])
107107
self.assertEqual(self.internal.get_frees(), ("x",))
108108

109-
# TODO: RUSTPYTHON
110-
@unittest.expectedFailure
111109
def test_globals(self):
112110
self.assertTrue(self.spam.lookup("glob").is_global())
113111
self.assertFalse(self.spam.lookup("glob").is_declared_global())

vm/src/stdlib/symtable.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ mod symtable {
174174

175175
#[pymethod]
176176
fn is_global(&self) -> bool {
177-
self.symbol.is_global()
177+
self.symbol.is_global() || (self.is_top_scope && self.symbol.is_bound())
178+
}
179+
180+
#[pymethod]
181+
fn is_declared_global(&self) -> bool {
182+
matches!(self.symbol.scope, SymbolScope::GlobalExplicit)
178183
}
179184

180185
#[pymethod]

0 commit comments

Comments
 (0)