diff options
Diffstat (limited to 'Lib/symtable.py')
-rw-r--r-- | Lib/symtable.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/symtable.py b/Lib/symtable.py index c7627a6ef6..5bea7cf615 100644 --- a/Lib/symtable.py +++ b/Lib/symtable.py @@ -1,7 +1,7 @@ """Interface to the compiler's internal symbol tables""" import _symtable -from _symtable import (USE, DEF_GLOBAL, DEF_LOCAL, DEF_PARAM, +from _symtable import (USE, DEF_GLOBAL, DEF_NONLOCAL, DEF_LOCAL, DEF_PARAM, DEF_IMPORT, DEF_BOUND, DEF_ANNOT, SCOPE_OFF, SCOPE_MASK, FREE, LOCAL, GLOBAL_IMPLICIT, GLOBAL_EXPLICIT, CELL) @@ -117,6 +117,7 @@ class Function(SymbolTable): __locals = None __frees = None __globals = None + __nonlocals = None def __idents_matching(self, test_func): return tuple(ident for ident in self.get_identifiers() @@ -141,6 +142,11 @@ class Function(SymbolTable): self.__globals = self.__idents_matching(test) return self.__globals + def get_nonlocals(self): + if self.__nonlocals is None: + self.__nonlocals = self.__idents_matching(lambda x:x & DEF_NONLOCAL) + return self.__nonlocals + def get_frees(self): if self.__frees is None: is_free = lambda x:((x >> SCOPE_OFF) & SCOPE_MASK) == FREE @@ -184,6 +190,9 @@ class Symbol(object): def is_global(self): return bool(self.__scope in (GLOBAL_IMPLICIT, GLOBAL_EXPLICIT)) + def is_nonlocal(self): + return bool(self.__flags & DEF_NONLOCAL) + def is_declared_global(self): return bool(self.__scope == GLOBAL_EXPLICIT) |