def AsyncFunctionDef(draw, statements) -> ast.AsyncFunctionDef: n = draw(name()) args = draw(arguments()) body = draw(lists(statements, min_size=1, max_size=3)) decorator_list = draw(lists(Name(), min_size=0, max_size=2)) returns = draw(none() | expression()) return ast.AsyncFunctionDef(n, args, body, decorator_list, returns)
def ClassDef(draw, statements) -> ast.ClassDef: n = draw(name()) bases = draw(lists(expression(), min_size=0, max_size=2)) keywords = draw(lists(keyword(), min_size=0, max_size=2)) assume(len({kw.arg for kw in keywords}) == len(keywords)) body = draw(lists(statements, min_size=1, max_size=3)) decorator_list = draw(lists(Name(), min_size=0, max_size=2)) return ast.ClassDef(name=n, bases=bases, keywords=keywords, body=body, decorator_list=decorator_list)
def AugAssign(draw): op = draw( sampled_from([ ast.Add(), ast.Sub(), ast.Mult(), ast.Div(), ast.FloorDiv(), ast.Mod(), ast.Pow(), ast.LShift(), ast.RShift(), ast.BitOr(), ast.BitXor(), ast.BitOr(), ast.BitAnd(), ast.MatMult() ])) return ast.AugAssign(target=draw(Name(ast.Store)), op=op, value=draw(expression()))
def AsyncWith(draw, statements) -> ast.AsyncWith: items = draw(lists(expression(), min_size=1, max_size=3)) body = draw(lists(statements, min_size=1, max_size=3)) return ast.AsyncWith( [ast.withitem(context_expr=i, optional_vars=None) for i in items], body)
def Delete(draw): return ast.Delete( targets=draw(lists(expression(), min_size=1, max_size=3)))
def Assert(draw): return ast.Assert(test=draw(expression()), msg=draw(expression()))
def Raise(draw): return ast.Raise(draw(none() | expression()), cause=None)
def Print(draw): return ast.Print(dest=None, value=draw(expression()), nl=not draw(booleans()))
def keyword(draw) -> ast.keyword: return ast.keyword(arg=draw(name()), value=draw(expression()))
def Return(draw) -> ast.Return: return ast.Return(draw(expression()))
def Expr(draw) -> ast.Expr: return ast.Expr(draw(expression()))
def While(draw, statements) -> ast.While: test = draw(expression()) body = draw(lists(statements, min_size=1, max_size=3)) orelse = draw(lists(statements, min_size=1, max_size=3)) return ast.While(test, body, orelse)
def AnnAssign(draw) -> ast.AnnAssign: target = draw(Name(ast.Store)) return ast.AnnAssign(target=target, annotation=draw(expression()), value=draw(expression()), simple=True)
def AsyncFor(draw, statements) -> ast.AsyncFor: target = draw(Name(ast.Store)) iter = draw(expression()) body = draw(lists(statements, min_size=1, max_size=3)) orelse = draw(lists(statements, min_size=1, max_size=3)) return ast.AsyncFor(target, iter, body, orelse)
def If(draw, statements) -> ast.If: body = draw(lists(statements, min_size=1, max_size=3)) orelse = draw(lists(statements, min_size=1, max_size=3)) return ast.If(test=draw(expression()), body=body, orelse=orelse)
def Assign(draw) -> ast.Assign: targets = draw(lists(Name(ast.Store), min_size=1, max_size=3)) return ast.Assign(targets=targets, value=draw(expression()))