本文整理匯總了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]