本文整理汇总了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")