[Python-checkins] bpo-40196: Fix a bug in the symtable when reporting inspecting global variables (GH-19391)
Pablo Galindo
webhook-mailer at python.org
Mon Apr 6 12:06:05 EDT 2020
https://github.com/python/cpython/commit/799d7d61a91eb0ad3256ef9a45a90029cef93b7c
commit: 799d7d61a91eb0ad3256ef9a45a90029cef93b7c
branch: master
author: Pablo Galindo <Pablogsal at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-04-06T17:05:57+01:00
summary:
bpo-40196: Fix a bug in the symtable when reporting inspecting global variables (GH-19391)
files:
A Misc/NEWS.d/next/Library/2020-04-06-11-05-13.bpo-40196.Jqowse.rst
M Lib/symtable.py
M Lib/test/test_symtable.py
diff --git a/Lib/symtable.py b/Lib/symtable.py
index 5bea7cf615548..ac0a64ff58f79 100644
--- a/Lib/symtable.py
+++ b/Lib/symtable.py
@@ -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)
diff --git a/Lib/test/test_symtable.py b/Lib/test/test_symtable.py
index bea2ce120ca96..98d718c8ab1b1 100644
--- a/Lib/test/test_symtable.py
+++ b/Lib/test/test_symtable.py
@@ -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())
@@ -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())
diff --git a/Misc/NEWS.d/next/Library/2020-04-06-11-05-13.bpo-40196.Jqowse.rst b/Misc/NEWS.d/next/Library/2020-04-06-11-05-13.bpo-40196.Jqowse.rst
new file mode 100644
index 0000000000000..c5fbd6e5ff3fb
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-04-06-11-05-13.bpo-40196.Jqowse.rst
@@ -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.
More information about the Python-checkins
mailing list