Python ast.Pass() Examples
The following are 30
code examples of ast.Pass().
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: topython.py From pyrser with GNU General Public License v3.0 | 6 votes |
def __exit_scope(self) -> ast.stmt: """Create the appropriate scope exiting statement. The documentation only shows one level and always uses 'return False' in examples. 'raise AltFalse()' within a try. 'break' within a loop. 'return False' otherwise. """ if self.in_optional: return ast.Pass() if self.in_try: return ast.Raise( ast.Call(ast.Name('AltFalse', ast.Load()), [], [], None, None), None) if self.in_loop: return ast.Break() return ast.Return(ast.Name('False', ast.Load())) #TODO(bps): find a better name to describe what this does
Example #2
Source File: topython.py From pyrser with GNU General Public License v3.0 | 6 votes |
def visit_Rep0N(self, node: parsing.Rep0N) -> [ast.stmt]: """Generates python code for a clause repeated 0 or more times. #If all clauses can be inlined while clause: pass while True: <code for the clause> """ cl_ast = self.visit(node.pt) if isinstance(cl_ast, ast.expr): return [ast.While(cl_ast, [ast.Pass()], [])] self.in_loop += 1 clause = self._clause(self.visit(node.pt)) self.in_loop -= 1 return [ast.While(ast.Name('True', ast.Load()), clause, [])]
Example #3
Source File: test_ast.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_try(self): p = ast.Pass() t = ast.Try([], [], [], [p]) self.stmt(t, "empty body on Try") t = ast.Try([ast.Expr(ast.Name("x", ast.Store()))], [], [], [p]) self.stmt(t, "must have Load context") t = ast.Try([p], [], [], []) self.stmt(t, "Try has neither except handlers nor finalbody") t = ast.Try([p], [], [p], [p]) self.stmt(t, "Try has orelse but no except handlers") t = ast.Try([p], [ast.ExceptHandler(None, "x", [])], [], []) self.stmt(t, "empty body on ExceptHandler") e = [ast.ExceptHandler(ast.Name("x", ast.Store()), "y", [p])] self.stmt(ast.Try([p], e, [], []), "must have Load context") e = [ast.ExceptHandler(None, "x", [p])] t = ast.Try([p], e, [ast.Expr(ast.Name("x", ast.Store()))], [p]) self.stmt(t, "must have Load context") t = ast.Try([p], e, [p], [ast.Expr(ast.Name("x", ast.Store()))]) self.stmt(t, "must have Load context")
Example #4
Source File: test_ast.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_classdef(self): def cls(bases=None, keywords=None, body=None, decorator_list=None): if bases is None: bases = [] if keywords is None: keywords = [] if body is None: body = [ast.Pass()] if decorator_list is None: decorator_list = [] return ast.ClassDef("myclass", bases, keywords, body, decorator_list) self.stmt(cls(bases=[ast.Name("x", ast.Store())]), "must have Load context") self.stmt(cls(keywords=[ast.keyword("x", ast.Name("x", ast.Store()))]), "must have Load context") self.stmt(cls(body=[]), "empty body on ClassDef") self.stmt(cls(body=[None]), "None disallowed") self.stmt(cls(decorator_list=[ast.Name("x", ast.Store())]), "must have Load context")
Example #5
Source File: onelinerizer.py From onelinerizer with MIT License | 6 votes |
def onelinerize(original): # original :: string # :: string t = ast.parse(original) table = symtable.symtable(original, '<string>', 'exec') original = original.strip() # If there's only one line anyways, be lazy if len(original.splitlines()) == 1 and \ len(t.body) == 1 and \ type(t.body[0]) in (ast.Delete, ast.Assign, ast.AugAssign, ast.Print, ast.Raise, ast.Assert, ast.Import, ast.ImportFrom, ast.Exec, ast.Global, ast.Expr, ast.Pass): return original return get_init_code(t, table)
Example #6
Source File: test_ast.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_classdef(self): def cls(bases=None, keywords=None, body=None, decorator_list=None): if bases is None: bases = [] if keywords is None: keywords = [] if body is None: body = [ast.Pass()] if decorator_list is None: decorator_list = [] return ast.ClassDef("myclass", bases, keywords, body, decorator_list) self.stmt(cls(bases=[ast.Name("x", ast.Store())]), "must have Load context") self.stmt(cls(keywords=[ast.keyword("x", ast.Name("x", ast.Store()))]), "must have Load context") self.stmt(cls(body=[]), "empty body on ClassDef") self.stmt(cls(body=[None]), "None disallowed") self.stmt(cls(decorator_list=[ast.Name("x", ast.Store())]), "must have Load context")
Example #7
Source File: test_ast.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_classdef(self): def cls(bases=None, keywords=None, starargs=None, kwargs=None, body=None, decorator_list=None): if bases is None: bases = [] if keywords is None: keywords = [] if body is None: body = [ast.Pass()] if decorator_list is None: decorator_list = [] return ast.ClassDef("myclass", bases, keywords, starargs, kwargs, body, decorator_list) self.stmt(cls(bases=[ast.Name("x", ast.Store())]), "must have Load context") self.stmt(cls(keywords=[ast.keyword("x", ast.Name("x", ast.Store()))]), "must have Load context") self.stmt(cls(starargs=ast.Name("x", ast.Store())), "must have Load context") self.stmt(cls(kwargs=ast.Name("x", ast.Store())), "must have Load context") self.stmt(cls(body=[]), "empty body on ClassDef") self.stmt(cls(body=[None]), "None disallowed") self.stmt(cls(decorator_list=[ast.Name("x", ast.Store())]), "must have Load context")
Example #8
Source File: test_ast.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_try(self): p = ast.Pass() t = ast.Try([], [], [], [p]) self.stmt(t, "empty body on Try") t = ast.Try([ast.Expr(ast.Name("x", ast.Store()))], [], [], [p]) self.stmt(t, "must have Load context") t = ast.Try([p], [], [], []) self.stmt(t, "Try has neither except handlers nor finalbody") t = ast.Try([p], [], [p], [p]) self.stmt(t, "Try has orelse but no except handlers") t = ast.Try([p], [ast.ExceptHandler(None, "x", [])], [], []) self.stmt(t, "empty body on ExceptHandler") e = [ast.ExceptHandler(ast.Name("x", ast.Store()), "y", [p])] self.stmt(ast.Try([p], e, [], []), "must have Load context") e = [ast.ExceptHandler(None, "x", [p])] t = ast.Try([p], e, [ast.Expr(ast.Name("x", ast.Store()))], [p]) self.stmt(t, "must have Load context") t = ast.Try([p], e, [p], [ast.Expr(ast.Name("x", ast.Store()))]) self.stmt(t, "must have Load context")
Example #9
Source File: test_ast.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_try(self): p = ast.Pass() t = ast.Try([], [], [], [p]) self.stmt(t, "empty body on Try") t = ast.Try([ast.Expr(ast.Name("x", ast.Store()))], [], [], [p]) self.stmt(t, "must have Load context") t = ast.Try([p], [], [], []) self.stmt(t, "Try has neither except handlers nor finalbody") t = ast.Try([p], [], [p], [p]) self.stmt(t, "Try has orelse but no except handlers") t = ast.Try([p], [ast.ExceptHandler(None, "x", [])], [], []) self.stmt(t, "empty body on ExceptHandler") e = [ast.ExceptHandler(ast.Name("x", ast.Store()), "y", [p])] self.stmt(ast.Try([p], e, [], []), "must have Load context") e = [ast.ExceptHandler(None, "x", [p])] t = ast.Try([p], e, [ast.Expr(ast.Name("x", ast.Store()))], [p]) self.stmt(t, "must have Load context") t = ast.Try([p], e, [p], [ast.Expr(ast.Name("x", ast.Store()))]) self.stmt(t, "must have Load context")
Example #10
Source File: test_ast.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_funcdef(self): a = ast.arguments([], None, [], [], None, []) f = ast.FunctionDef("x", a, [], [], None) self.stmt(f, "empty body on FunctionDef") f = ast.FunctionDef("x", a, [ast.Pass()], [ast.Name("x", ast.Store())], None) self.stmt(f, "must have Load context") f = ast.FunctionDef("x", a, [ast.Pass()], [], ast.Name("x", ast.Store())) self.stmt(f, "must have Load context") def fac(args): return ast.FunctionDef("x", args, [ast.Pass()], [], None) self._check_arguments(fac, self.stmt)
Example #11
Source File: test_ast.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_if(self): self.stmt(ast.If(ast.Num(3), [], []), "empty body on If") i = ast.If(ast.Name("x", ast.Store()), [ast.Pass()], []) self.stmt(i, "must have Load context") i = ast.If(ast.Num(3), [ast.Expr(ast.Name("x", ast.Store()))], []) self.stmt(i, "must have Load context") i = ast.If(ast.Num(3), [ast.Pass()], [ast.Expr(ast.Name("x", ast.Store()))]) self.stmt(i, "must have Load context")
Example #12
Source File: test_ast.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_for(self): x = ast.Name("x", ast.Store()) y = ast.Name("y", ast.Load()) p = ast.Pass() self.stmt(ast.For(x, y, [], []), "empty body on For") self.stmt(ast.For(ast.Name("x", ast.Load()), y, [p], []), "must have Store context") self.stmt(ast.For(x, ast.Name("y", ast.Store()), [p], []), "must have Load context") e = ast.Expr(ast.Name("x", ast.Store())) self.stmt(ast.For(x, y, [e], []), "must have Load context") self.stmt(ast.For(x, y, [p], [e]), "must have Load context")
Example #13
Source File: test_ast.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_while(self): self.stmt(ast.While(ast.Num(3), [], []), "empty body on While") self.stmt(ast.While(ast.Name("x", ast.Store()), [ast.Pass()], []), "must have Load context") self.stmt(ast.While(ast.Num(3), [ast.Pass()], [ast.Expr(ast.Name("x", ast.Store()))]), "must have Load context")
Example #14
Source File: test_ast.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_if(self): self.stmt(ast.If(ast.Num(3), [], []), "empty body on If") i = ast.If(ast.Name("x", ast.Store()), [ast.Pass()], []) self.stmt(i, "must have Load context") i = ast.If(ast.Num(3), [ast.Expr(ast.Name("x", ast.Store()))], []) self.stmt(i, "must have Load context") i = ast.If(ast.Num(3), [ast.Pass()], [ast.Expr(ast.Name("x", ast.Store()))]) self.stmt(i, "must have Load context")
Example #15
Source File: yacc.py From yaksok with BSD 3-Clause "New" or "Revised" License | 5 votes |
def p_pass_stmt(t): '''stmt : PASS NEWLINE''' t[0] = ast.Pass() t[0].lineno = t.lineno(1) t[0].col_offset = -1 # XXX
Example #16
Source File: yacc.py From yaksok with BSD 3-Clause "New" or "Revised" License | 5 votes |
def p_if_else_stmt(t): '''stmt : IF expression ELSE suite''' pass_ast = ast.Pass() pass_ast.lineno = t.lineno(1) pass_ast.col_offset = -1 # XXX t[0] = ast.If(t[2], [pass_ast], t[4]) t[0].lineno = t.lineno(4) t[0].col_offset = -1 # XXX
Example #17
Source File: python2ir.py From ppci with BSD 2-Clause "Simplified" License | 5 votes |
def gen_statement(self, statement): """ Generate code for a statement """ if isinstance(statement, list): for inner_statement in statement: self.gen_statement(inner_statement) else: with self.use_location(statement): if isinstance(statement, ast.Pass): pass # No comments :) elif isinstance(statement, ast.Return): self.gen_return(statement) elif isinstance(statement, ast.If): self.gen_if(statement) elif isinstance(statement, ast.While): self.gen_while(statement) elif isinstance(statement, ast.Break): self.gen_break(statement) elif isinstance(statement, ast.Continue): self.gen_continue(statement) elif isinstance(statement, ast.For): self.gen_for(statement) elif isinstance(statement, ast.Assign): self.gen_assign(statement) elif isinstance(statement, ast.Expr): self.gen_expr(statement.value) elif isinstance(statement, ast.AugAssign): self.gen_aug_assign(statement) else: # pragma: no cover self.not_impl(statement)
Example #18
Source File: definitions.py From vkbottle with MIT License | 5 votes |
def pass_expr(d: ast.Pass): return ""
Example #19
Source File: tree.py From dlint with BSD 3-Clause "New" or "Revised" License | 5 votes |
def function_is_empty(function): def raise_or_pass_or_docstring(node): return ( isinstance(node, ast.Raise) or isinstance(node, ast.Pass) or (isinstance(node, ast.Expr) and isinstance(node.value, ast.Str)) ) return all( raise_or_pass_or_docstring(child) for child in function.body )
Example #20
Source File: cps.py From kappa with BSD 2-Clause "Simplified" License | 5 votes |
def visit_Pass(self, pass_stmt: ast.Pass, _ctx: CPSTransformerContext) -> VisitReturnT: return pass_stmt, []
Example #21
Source File: flatten.py From kappa with BSD 2-Clause "Simplified" License | 5 votes |
def visit_Pass(self, pass_stmt: ast.Pass) -> ActionsT: return [pass_stmt] # Slices
Example #22
Source File: liveness.py From kappa with BSD 2-Clause "Simplified" License | 5 votes |
def visit_Pass(self, _pass_stmt: ast.Pass) -> None: pass
Example #23
Source File: parser.py From myia with MIT License | 5 votes |
def process_Pass(self, block: "Block", node: ast.Pass) -> "Block": """Process a pass statement.""" return block
Example #24
Source File: topython.py From pyrser with GNU General Public License v3.0 | 5 votes |
def visit_Alt(self, node: parsing.Alt) -> [ast.stmt]: """Generates python code for alternatives. try: try: <code for clause> #raise AltFalse when alternative is False raise AltTrue() except AltFalse: pass return False except AltTrue: pass """ clauses = [self.visit(clause) for clause in node.ptlist] for clause in clauses: if not isinstance(clause, ast.expr): break else: return ast.BoolOp(ast.Or(), clauses) res = ast.Try([], [ast.ExceptHandler( ast.Name('AltTrue', ast.Load()), None, [ast.Pass()])], [], []) alt_true = [ast.Raise(ast.Call( ast.Name('AltTrue', ast.Load()), [], [], None, None), None)] alt_false = [ast.ExceptHandler( ast.Name('AltFalse', ast.Load()), None, [ast.Pass()])] self.in_try += 1 for clause in node.ptlist: res.body.append( ast.Try(self._clause(self.visit(clause)) + alt_true, alt_false, [], [])) self.in_try -= 1 res.body.append(self.__exit_scope()) return [res]
Example #25
Source File: node_transformers.py From pynt with GNU General Public License v3.0 | 5 votes |
def visit_Continue(self, cont): """ >>> self = FirstPassForSimple('foo') >>> code = 'continue' >>> module = ast.parse(code) >>> cont, = module.body """ return ast.Pass()
Example #26
Source File: node_transformers.py From pynt with GNU General Public License v3.0 | 5 votes |
def visit_Break(self, broken): """ >>> self = FirstPassForSimple('foo') >>> code = 'break' >>> module = ast.parse(code) >>> broken, = module.body """ return ast.Pass()
Example #27
Source File: node_transformers.py From pynt with GNU General Public License v3.0 | 5 votes |
def visit_For(self, loop_): """ >>> self = FirstPassFor(buffer='foo') >>> code = ''' ... ... for i in range(5): ... for j in range(5): ... k = i + j ... print(k) ... ... ''' >>> tree = ast.parse(code) >>> loop_, = tree.body """ loop = self.generic_visit(loop_) var = ast.Name(id=__random_string__(), ctx=ast.Store()) assign = ast.Assign(targets=[var], value=ast.Call(func=ast.Name(id='iter', ctx=ast.Load()), args=[loop.iter], keywords=[])) first_pass = ast.Try( body=[ast.Assign(targets=[loop.target], value=ast.Call(func=ast.Name(id='next', ctx=ast.Load()), args=[ast.Name(id=var, ctx=ast.Load())], keywords=[]))], handlers=[ast.ExceptHandler(type=ast.Name(id='StopIteration', ctx=ast.Load()), name=None, body=[ast.Pass()])], orelse=loop.body, finalbody=[] ) content = f'`for {astor.to_source(loop.target).strip()} in {astor.to_source(loop.iter).strip()} ...`' return [ make_annotation(buffer=self.buffer, content=content, cell_type='2', lineno=loop.lineno), ast.Expr(loop.iter), assign, first_pass ]
Example #28
Source File: test_ast.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_funcdef(self): a = ast.arguments([], None, [], [], None, []) f = ast.FunctionDef("x", a, [], [], None) self.stmt(f, "empty body on FunctionDef") f = ast.FunctionDef("x", a, [ast.Pass()], [ast.Name("x", ast.Store())], None) self.stmt(f, "must have Load context") f = ast.FunctionDef("x", a, [ast.Pass()], [], ast.Name("x", ast.Store())) self.stmt(f, "must have Load context") def fac(args): return ast.FunctionDef("x", args, [ast.Pass()], [], None) self._check_arguments(fac, self.stmt)
Example #29
Source File: test_ast.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_for(self): x = ast.Name("x", ast.Store()) y = ast.Name("y", ast.Load()) p = ast.Pass() self.stmt(ast.For(x, y, [], []), "empty body on For") self.stmt(ast.For(ast.Name("x", ast.Load()), y, [p], []), "must have Store context") self.stmt(ast.For(x, ast.Name("y", ast.Store()), [p], []), "must have Load context") e = ast.Expr(ast.Name("x", ast.Store())) self.stmt(ast.For(x, y, [e], []), "must have Load context") self.stmt(ast.For(x, y, [p], [e]), "must have Load context")
Example #30
Source File: test_ast.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_while(self): self.stmt(ast.While(ast.Num(3), [], []), "empty body on While") self.stmt(ast.While(ast.Name("x", ast.Store()), [ast.Pass()], []), "must have Load context") self.stmt(ast.While(ast.Num(3), [ast.Pass()], [ast.Expr(ast.Name("x", ast.Store()))]), "must have Load context")