Kaydet (Commit) 1c157ea9 authored tarafından Jeremy Hylton's avatar Jeremy Hylton

Add is_declared_global() which distinguishes between implicit and

explicit global variables.
üst 9d2ee5de
...@@ -190,6 +190,9 @@ class Symbol(object): ...@@ -190,6 +190,9 @@ class Symbol(object):
def is_global(self): def is_global(self):
return bool(self.__scope in (GLOBAL_IMPLICIT, GLOBAL_EXPLICIT)) return bool(self.__scope in (GLOBAL_IMPLICIT, GLOBAL_EXPLICIT))
def is_declared_global(self):
return bool(self.__scope == GLOBAL_EXPLICIT)
def is_local(self): def is_local(self):
return bool(self.__flags & DEF_BOUND) return bool(self.__flags & DEF_BOUND)
......
...@@ -98,7 +98,9 @@ class SymtableTest(unittest.TestCase): ...@@ -98,7 +98,9 @@ class SymtableTest(unittest.TestCase):
def test_globals(self): def test_globals(self):
self.assertTrue(self.spam.lookup("glob").is_global()) 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_global())
self.assertTrue(self.spam.lookup("bar").is_declared_global())
self.assertFalse(self.internal.lookup("x").is_global()) self.assertFalse(self.internal.lookup("x").is_global())
self.assertFalse(self.Mine.lookup("instance_var").is_global()) self.assertFalse(self.Mine.lookup("instance_var").is_global())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment