Skip to content

Commit 717f166

Browse files
bpo-40196: Fix a bug in the symtable when reporting inspecting global variables (GH-19391)
(cherry picked from commit 799d7d6) Co-authored-by: Pablo Galindo <[email protected]>
1 parent 44c1cdd commit 717f166

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Lib/symtable.py

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

190190
def is_local(self):
191-
return bool(self.__flags & DEF_BOUND)
191+
return bool(self.__scope in (LOCAL, CELL))
192192

193193
def is_annotated(self):
194194
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
@@ -92,10 +92,14 @@ def test_globals(self):
9292
self.assertTrue(self.spam.lookup("bar").is_declared_global())
9393
self.assertFalse(self.internal.lookup("x").is_global())
9494
self.assertFalse(self.Mine.lookup("instance_var").is_global())
95+
self.assertTrue(self.spam.lookup("bar").is_global())
9596

9697
def test_local(self):
9798
self.assertTrue(self.spam.lookup("x").is_local())
98-
self.assertFalse(self.internal.lookup("x").is_local())
99+
self.assertFalse(self.spam.lookup("bar").is_local())
100+
101+
def test_free(self):
102+
self.assertTrue(self.internal.lookup("x").is_free())
99103

100104
def test_referenced(self):
101105
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)