summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-06-28 19:27:55 +0000
committerBenjamin Peterson <benjamin@python.org>2009-06-28 19:27:55 +0000
commit552e7a7e2f526fa0637a3e14f47354c567dfe26e (patch)
tree73731cee6c1c7bfb93328ce3a85413166ce75adf
parent8f7b94eae96c22a63f8c5768c6e3d42004994e18 (diff)
downloadcpython-git-552e7a7e2f526fa0637a3e14f47354c567dfe26e.tar.gz
return locals and cells in get_locals() not bound globals, though
-rw-r--r--Lib/symtable.py6
-rw-r--r--Lib/test/test_symtable.py2
2 files changed, 5 insertions, 3 deletions
diff --git a/Lib/symtable.py b/Lib/symtable.py
index 44d70a35fd..ca73f58651 100644
--- a/Lib/symtable.py
+++ b/Lib/symtable.py
@@ -3,7 +3,7 @@
import _symtable
from _symtable import (USE, DEF_GLOBAL, DEF_LOCAL, DEF_PARAM,
DEF_IMPORT, DEF_BOUND, OPT_IMPORT_STAR, OPT_EXEC, OPT_BARE_EXEC,
- SCOPE_OFF, SCOPE_MASK, FREE, GLOBAL_IMPLICIT, GLOBAL_EXPLICIT)
+ SCOPE_OFF, SCOPE_MASK, FREE, GLOBAL_IMPLICIT, GLOBAL_EXPLICIT, CELL, LOCAL)
import weakref
@@ -137,7 +137,9 @@ class Function(SymbolTable):
def get_locals(self):
if self.__locals is None:
- self.__locals = self.__idents_matching(lambda x:x & DEF_BOUND)
+ locs = (LOCAL, CELL)
+ test = lambda x: ((x >> SCOPE_OFF) & SCOPE_MASK) in locs
+ self.__locals = self.__idents_matching(test)
return self.__locals
def get_globals(self):
diff --git a/Lib/test/test_symtable.py b/Lib/test/test_symtable.py
index 792d9c3343..2de30ae664 100644
--- a/Lib/test/test_symtable.py
+++ b/Lib/test/test_symtable.py
@@ -92,7 +92,7 @@ class SymtableTest(unittest.TestCase):
func = self.spam
self.assertEqual(func.get_parameters(), ("a", "b", "kw", "var"))
self.assertEqual(func.get_locals(),
- ("a", "b", "bar", "internal", "kw", "var", "x"))
+ ("a", "b", "internal", "kw", "var", "x"))
self.assertEqual(func.get_globals(), ("bar", "glob"))
self.assertEqual(self.internal.get_frees(), ("x",))