diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/tools/python3/src/Lib/symtable.py | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Lib/symtable.py')
-rw-r--r-- | contrib/tools/python3/src/Lib/symtable.py | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/contrib/tools/python3/src/Lib/symtable.py b/contrib/tools/python3/src/Lib/symtable.py index 521540fe9e..8fc60f9812 100644 --- a/contrib/tools/python3/src/Lib/symtable.py +++ b/contrib/tools/python3/src/Lib/symtable.py @@ -1,7 +1,7 @@ """Interface to the compiler's internal symbol tables""" import _symtable -from _symtable import (USE, DEF_GLOBAL, DEF_NONLOCAL, 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) @@ -34,7 +34,7 @@ class SymbolTableFactory: _newSymbolTable = SymbolTableFactory() -class SymbolTable: +class SymbolTable: def __init__(self, raw_table, filename): self._table = raw_table @@ -47,7 +47,7 @@ class SymbolTable: else: kind = "%s " % self.__class__.__name__ - if self._table.name == "top": + if self._table.name == "top": return "<{0}SymbolTable for module {1}>".format(kind, self._filename) else: return "<{0}SymbolTable for {1} in {2}>".format(kind, @@ -90,9 +90,9 @@ class SymbolTable: if sym is None: flags = self._table.symbols[name] namespaces = self.__check_children(name) - module_scope = (self._table.name == "top") - sym = self._symbols[name] = Symbol(name, flags, namespaces, - module_scope=module_scope) + module_scope = (self._table.name == "top") + sym = self._symbols[name] = Symbol(name, flags, namespaces, + module_scope=module_scope) return sym def get_symbols(self): @@ -115,7 +115,7 @@ class Function(SymbolTable): __locals = None __frees = None __globals = None - __nonlocals = None + __nonlocals = None def __idents_matching(self, test_func): return tuple(ident for ident in self.get_identifiers() @@ -140,11 +140,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_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 @@ -165,14 +165,14 @@ class Class(SymbolTable): return self.__methods -class Symbol: +class Symbol: - def __init__(self, name, flags, namespaces=None, *, module_scope=False): + def __init__(self, name, flags, namespaces=None, *, module_scope=False): self.__name = name self.__flags = flags self.__scope = (flags >> SCOPE_OFF) & SCOPE_MASK # like PyST_GetScope() self.__namespaces = namespaces or () - self.__module_scope = module_scope + self.__module_scope = module_scope def __repr__(self): return "<symbol {0!r}>".format(self.__name) @@ -187,22 +187,22 @@ class Symbol: return bool(self.__flags & DEF_PARAM) def is_global(self): - """Return *True* if the sysmbol is global. - """ - return bool(self.__scope in (GLOBAL_IMPLICIT, GLOBAL_EXPLICIT) - or (self.__module_scope and self.__flags & DEF_BOUND)) - - def is_nonlocal(self): - return bool(self.__flags & DEF_NONLOCAL) - + """Return *True* if the sysmbol is global. + """ + return bool(self.__scope in (GLOBAL_IMPLICIT, GLOBAL_EXPLICIT) + or (self.__module_scope and self.__flags & DEF_BOUND)) + + def is_nonlocal(self): + return bool(self.__flags & DEF_NONLOCAL) + def is_declared_global(self): return bool(self.__scope == GLOBAL_EXPLICIT) def is_local(self): - """Return *True* if the symbol is local. - """ - return bool(self.__scope in (LOCAL, CELL) - or (self.__module_scope and self.__flags & DEF_BOUND)) + """Return *True* if the symbol is local. + """ + return bool(self.__scope in (LOCAL, CELL) + or (self.__module_scope and self.__flags & DEF_BOUND)) def is_annotated(self): return bool(self.__flags & DEF_ANNOT) |