]> granicus.if.org Git - python/commitdiff
Add is_declared_global() which distinguishes between implicit and
authorJeremy Hylton <jeremy@alum.mit.edu>
Tue, 31 Mar 2009 13:17:03 +0000 (13:17 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Tue, 31 Mar 2009 13:17:03 +0000 (13:17 +0000)
explicit global variables.

Lib/symtable.py
Lib/test/test_symtable.py

index a8112ff94238fc166fcfdf41ba8932cbfadb386a..44d70a35fda5a1c3dc6cb314d5be27077f7262d8 100644 (file)
@@ -190,6 +190,9 @@ class Symbol(object):
     def is_global(self):
         return bool(self.__scope in (GLOBAL_IMPLICIT, GLOBAL_EXPLICIT))
 
+    def is_declared_global(self):
+        return bool(self.__scope == GLOBAL_EXPLICIT)
+
     def is_local(self):
         return bool(self.__flags & DEF_BOUND)
 
index cdb216b0babc77f867d146d47cc212f32395fcda..792d9c3343e84d66948aad77b56a46fa099c7f03 100644 (file)
@@ -98,7 +98,9 @@ class SymtableTest(unittest.TestCase):
 
     def test_globals(self):
         self.assertTrue(self.spam.lookup("glob").is_global())
+        self.assertFalse(self.spam.lookup("glob").is_declared_global())
         self.assertTrue(self.spam.lookup("bar").is_global())
+        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())