本文整理汇总了Python中_ast.Try方法的典型用法代码示例。如果您正苦于以下问题:Python _ast.Try方法的具体用法?Python _ast.Try怎么用?Python _ast.Try使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_ast
的用法示例。
在下文中一共展示了_ast.Try方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CONTINUE
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Try [as 别名]
def CONTINUE(self, node):
# Walk the tree up until we see a loop (OK), a function or class
# definition (not OK), for 'continue', a finally block (not OK), or
# the top module scope (not OK)
n = node
while hasattr(n, 'parent'):
n, n_child = n.parent, n
if isinstance(n, LOOP_TYPES):
# Doesn't apply unless it's in the loop itself
if n_child not in n.orelse:
return
if isinstance(n, (ast.FunctionDef, ast.ClassDef)):
break
# Handle Try/TryFinally difference in Python < and >= 3.3
if hasattr(n, 'finalbody') and isinstance(node, ast.Continue):
if n_child in n.finalbody:
self.report(messages.ContinueInFinally, node)
return
if isinstance(node, ast.Continue):
self.report(messages.ContinueOutsideLoop, node)
else: # ast.Break
self.report(messages.BreakOutsideLoop, node)
示例2: visit_try
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Try [as 别名]
def visit_try(self, node: _ast.Try):
raise BadSyntax('You can not use `try` syntax')
示例3: getNodeType
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Try [as 别名]
def getNodeType(node_class):
return node_class.__name__.upper()
# Python >= 3.3 uses ast.Try instead of (ast.TryExcept + ast.TryFinally)
示例4: getAlternatives
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Try [as 别名]
def getAlternatives(n):
if isinstance(n, ast.If):
return [n.body]
if isinstance(n, ast.Try):
return [n.body + n.orelse] + [[hdl] for hdl in n.handlers]