Skip to content

Commit 799d7d6

Browse files
authored
bpo-40196: Fix a bug in the symtable when reporting inspecting global variables (GH-19391)
1 parent 38aefc5 commit 799d7d6

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

Lib/symtable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def is_declared_global(self):
197197
return bool(self.__scope == GLOBAL_EXPLICIT)
198198

199199
def is_local(self):
200-
return bool(self.__flags & DEF_BOUND)
200+
return bool(self.__scope in (LOCAL, CELL))
201201

202202
def is_annotated(self):
203203
return bool(self.__flags & DEF_ANNOT)

Lib/test/test_symtable.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def test_globals(self):
9999
self.assertTrue(self.spam.lookup("bar").is_declared_global())
100100
self.assertFalse(self.internal.lookup("x").is_global())
101101
self.assertFalse(self.Mine.lookup("instance_var").is_global())
102+
self.assertTrue(self.spam.lookup("bar").is_global())
102103

103104
def test_nonlocal(self):
104105
self.assertFalse(self.spam.lookup("some_var").is_nonlocal())
@@ -108,7 +109,10 @@ def test_nonlocal(self):
108109

109110
def test_local(self):
110111
self.assertTrue(self.spam.lookup("x").is_local())
111-
self.assertFalse(self.internal.lookup("x").is_local())
112+
self.assertFalse(self.spam.lookup("bar").is_local())
113+
114+
def test_free(self):
115+
self.assertTrue(self.internal.lookup("x").is_free())
112116

113117
def test_referenced(self):
114118
self.assertTrue(self.internal.lookup("x").is_referenced())
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a bug in the :mod:`symtable` module that was causing incorrectly report
2+
global variables as local. Patch by Pablo Galindo.

0 commit comments

Comments
 (0)