[Python-checkins] r70801 - in python/trunk/Lib: symtable.py test/test_symtable.py

jeremy.hylton python-checkins at python.org
Tue Mar 31 15:17:03 CEST 2009


Author: jeremy.hylton
Date: Tue Mar 31 15:17:03 2009
New Revision: 70801

Log:
Add is_declared_global() which distinguishes between implicit and
explicit global variables.


Modified:
   python/trunk/Lib/symtable.py
   python/trunk/Lib/test/test_symtable.py

Modified: python/trunk/Lib/symtable.py
==============================================================================
--- python/trunk/Lib/symtable.py	(original)
+++ python/trunk/Lib/symtable.py	Tue Mar 31 15:17:03 2009
@@ -190,6 +190,9 @@
     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)
 

Modified: python/trunk/Lib/test/test_symtable.py
==============================================================================
--- python/trunk/Lib/test/test_symtable.py	(original)
+++ python/trunk/Lib/test/test_symtable.py	Tue Mar 31 15:17:03 2009
@@ -98,7 +98,9 @@
 
     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())
 


More information about the Python-checkins mailing list