Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/symtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def is_declared_global(self):
return bool(self.__scope == GLOBAL_EXPLICIT)

def is_local(self):
return bool(self.__flags & DEF_BOUND)
return bool(self.__scope in (LOCAL, CELL))

def is_annotated(self):
return bool(self.__flags & DEF_ANNOT)
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_symtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def test_globals(self):
self.assertTrue(self.spam.lookup("bar").is_declared_global())
self.assertFalse(self.internal.lookup("x").is_global())
self.assertFalse(self.Mine.lookup("instance_var").is_global())
self.assertTrue(self.spam.lookup("bar").is_global())

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

def test_local(self):
self.assertTrue(self.spam.lookup("x").is_local())
self.assertFalse(self.internal.lookup("x").is_local())
self.assertFalse(self.spam.lookup("bar").is_local())

def test_free(self):
self.assertTrue(self.internal.lookup("x").is_free())

def test_referenced(self):
self.assertTrue(self.internal.lookup("x").is_referenced())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a bug in the :mod:`symtable` module that was causing incorrectly report
global variables as local. Patch by Pablo Galindo.