Esempio n. 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)
Esempio n. 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)))
Esempio n. 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)
Esempio n. 4
0
def keyword(draw) -> ast.keyword:
    return ast.keyword(arg=draw(name()), value=draw(expression()))
Esempio n. 5
0
def ImportFrom(draw) -> ast.ImportFrom:
    return ast.ImportFrom(module=draw(name()),
                          names=draw(lists(alias(), min_size=1, max_size=3)),
                          level=draw(integers(min_value=0, max_value=2)))
Esempio n. 6
0
def alias(draw) -> ast.alias:
    return ast.alias(name=draw(name()), asname=draw(none() | name()))
Esempio n. 7
0
def Nonlocal(draw) -> ast.Nonlocal:
    return ast.Nonlocal(draw(lists(name(), min_size=1, max_size=3)))
Esempio n. 8
0
def Global(draw) -> ast.Global:
    return ast.Global(draw(lists(name(), min_size=1, max_size=3)))