예제 #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)
예제 #2
0
def ExceptHandler(draw, statements) -> ast.ExceptHandler:
    t = draw(none() | Name())

    n = None
    if t is not None:
        n = draw(name())

    return ast.ExceptHandler(type=t,
                             name=n,
                             body=draw(
                                 lists(statements, min_size=1, max_size=3)))
예제 #3
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)
예제 #4
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()))
예제 #5
0
def AnnAssign(draw) -> ast.AnnAssign:
    target = draw(Name(ast.Store))
    return ast.AnnAssign(target=target,
                         annotation=draw(expression()),
                         value=draw(expression()),
                         simple=True)
예제 #6
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)
예제 #7
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()))