本文整理匯總了Python中ast.Nonlocal方法的典型用法代碼示例。如果您正苦於以下問題:Python ast.Nonlocal方法的具體用法?Python ast.Nonlocal怎麽用?Python ast.Nonlocal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ast
的用法示例。
在下文中一共展示了ast.Nonlocal方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: make_global_and_nonlocal_decls
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Nonlocal [as 別名]
def make_global_and_nonlocal_decls(code_instrs):
"""
Find all STORE_GLOBAL and STORE_DEREF instructions in `instrs` and convert
them into a canonical list of `ast.Global` and `ast.Nonlocal` declarations.
"""
globals_ = sorted(set(
i.arg for i in code_instrs if isinstance(i, instrs.STORE_GLOBAL)
))
nonlocals = sorted(set(
i.arg for i in code_instrs
if isinstance(i, instrs.STORE_DEREF) and i.vartype == 'free'
))
out = []
if globals_:
out.append(ast.Global(names=globals_))
if nonlocals:
out.append(ast.Nonlocal(names=nonlocals))
return out
示例2: _visit_nonlocal
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Nonlocal [as 別名]
def _visit_nonlocal(self, node: ast.Nonlocal):
self.symtable.explicit_nonlocals.update(node.names)
return node
示例3: test_nonlocal
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Nonlocal [as 別名]
def test_nonlocal(self):
self.stmt(ast.Nonlocal([]), "empty names on Nonlocal")