]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40196: Fix a bug in the symtable when reporting inspecting global variables ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 6 Apr 2020 16:41:24 +0000 (09:41 -0700)
committerGitHub <noreply@github.com>
Mon, 6 Apr 2020 16:41:24 +0000 (09:41 -0700)
(cherry picked from commit 799d7d61a91eb0ad3256ef9a45a90029cef93b7c)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Lib/symtable.py
Lib/test/test_symtable.py
Misc/NEWS.d/next/Library/2020-04-06-11-05-13.bpo-40196.Jqowse.rst [new file with mode: 0644]

index c7627a6ef68856a68a87a3c19942461e8dcc9cff..42ab725645363f0c9cc7f0a1be7e2f065ff8698e 100644 (file)
@@ -188,7 +188,7 @@ class Symbol(object):
         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)
index dfaee173ef725bf2372283010f34ac956212131f..aa99e86e4bce4c807d37d4f8d53957aef51ad121 100644 (file)
@@ -92,10 +92,14 @@ class SymtableTest(unittest.TestCase):
         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_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 (file)
index 0000000..c5fbd6e
--- /dev/null
@@ -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.