Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
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()))
Beispiel #4
0
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)
Beispiel #5
0
def Delete(draw):
    return ast.Delete(
        targets=draw(lists(expression(), min_size=1, max_size=3)))
Beispiel #6
0
def Assert(draw):
    return ast.Assert(test=draw(expression()), msg=draw(expression()))
Beispiel #7
0
def Raise(draw):
    return ast.Raise(draw(none() | expression()), cause=None)
Beispiel #8
0
def Print(draw):
    return ast.Print(dest=None,
                     value=draw(expression()),
                     nl=not draw(booleans()))
Beispiel #9
0
def keyword(draw) -> ast.keyword:
    return ast.keyword(arg=draw(name()), value=draw(expression()))
Beispiel #10
0
def Return(draw) -> ast.Return:
    return ast.Return(draw(expression()))
Beispiel #11
0
def Expr(draw) -> ast.Expr:
    return ast.Expr(draw(expression()))
Beispiel #12
0
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)
Beispiel #13
0
def AnnAssign(draw) -> ast.AnnAssign:
    target = draw(Name(ast.Store))
    return ast.AnnAssign(target=target,
                         annotation=draw(expression()),
                         value=draw(expression()),
                         simple=True)
Beispiel #14
0
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)
Beispiel #15
0
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)
Beispiel #16
0
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()))