From 1c157ea984afd94ea3aa9ceeaf14e4de7b0583b4 Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Tue, 31 Mar 2009 13:17:03 +0000 Subject: Add is_declared_global() which distinguishes between implicit and explicit global variables. --- Lib/symtable.py | 3 +++ Lib/test/test_symtable.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Lib/symtable.py b/Lib/symtable.py index a8112ff..44d70a3 100644 --- a/Lib/symtable.py +++ b/Lib/symtable.py @@ -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) diff --git a/Lib/test/test_symtable.py b/Lib/test/test_symtable.py index cdb216b..792d9c3 100644 --- a/Lib/test/test_symtable.py +++ b/Lib/test/test_symtable.py @@ -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()) -- cgit v0.12