Python _ast.Try() Examples
The following are 6
code examples of _ast.Try().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
_ast
, or try the search function
.
Example #1
Source File: checker.py From blackmamba with MIT License | 6 votes |
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)
Example #2
Source File: calc.py From yui with GNU Affero General Public License v3.0 | 5 votes |
def visit_try(self, node: _ast.Try): raise BadSyntax('You can not use `try` syntax')
Example #3
Source File: checker.py From blackmamba with MIT License | 5 votes |
def getNodeType(node_class): return node_class.__name__.upper() # Python >= 3.3 uses ast.Try instead of (ast.TryExcept + ast.TryFinally)
Example #4
Source File: checker.py From blackmamba with MIT License | 5 votes |
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]
Example #5
Source File: checker.py From Transcrypt with Apache License 2.0 | 5 votes |
def getNodeType(node_class): return node_class.__name__.upper() # Python >= 3.3 uses ast.Try instead of (ast.TryExcept + ast.TryFinally)
Example #6
Source File: checker.py From Transcrypt with Apache License 2.0 | 5 votes |
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]