Example #1
0
def build_param(ctx, py_arg, self_name, kwarg_only, pdt_arg_type=None):
    # NB: In Python3 py_arg is a pair of (str arg, expr? annotation)
    name = py_arg.arg
    r = ctx.make_range(py_arg.lineno, py_arg.col_offset, py_arg.col_offset + len(name))
    if getattr(py_arg, 'annotation', None) is not None:
        annotation_expr = build_expr(ctx, py_arg.annotation)
    elif pdt_arg_type:
        annotation_expr = Var(Ident(r, pdt_arg_type))
    elif self_name is not None and name == 'self':
        annotation_expr = Var(Ident(r, self_name))
    else:
        annotation_expr = EmptyTypeAnnotation(r)
    return Param(annotation_expr, Ident(r, name), kwarg_only)
Example #2
0
 def build_Print(ctx, stmt):
     r = ctx.make_range(stmt.lineno, stmt.col_offset,
                        stmt.col_offset + len("print"))
     if stmt.dest:
         raise NotSupportedError(
             r,
             "print statements with non-default destinations aren't supported"
         )
     args = [build_expr(ctx, val) for val in stmt.values]
     return ExprStmt(Apply(Var(Ident(r, "print")), args, []))
Example #3
0
 def build_Name(ctx, expr):
     r = ctx.make_range(expr.lineno, expr.col_offset, expr.col_offset + len(expr.id))
     if expr.id.startswith(_reserved_prefix):
         raise NotSupportedError(r, "names of variables used in JIT-ed functions "
                                    "can't start with " + _reserved_prefix)
     if expr.id == "True":
         return TrueLiteral(r)
     elif expr.id == "False":
         return FalseLiteral(r)
     elif expr.id == "None":
         return NoneLiteral(r)
     return Var(Ident(r, expr.id))