def annotate(self, source): source = textwrap.dedent(source.lstrip('\n')) pytype_options = config.Options.create( python_version=self.python_version) module = annotate_ast.annotate_source(source, ast, pytype_options) return module
def annotate(self, source): source = textwrap.dedent(source.lstrip('\n')) ast_factory = lambda unused_options: ast pytype_options = config.Options.create( python_version=self.python_version) module = annotate_ast.annotate_source(source, ast_factory, pytype_options) return module
def main(): parser = argparse.ArgumentParser(usage='%(prog)s [options] input') args, options = arg_parser.add_pytype_and_parse(parser, sys.argv[1:]) filename = args.inputs[0] with open(filename, 'r') as f: src = f.read() module = annotate_ast.annotate_source(src, ast3, options) print(debug.dump(module, ast3))
def annotate(self, source): source = textwrap.dedent(source.lstrip('\n')) filename = 'unused.py' ast_factory = lambda unused_options: ast pytype_options = config.Options.create(filename) pytype_options.tweak(version=self.python_version) module = annotate_ast.annotate_source(source, ast_factory, pytype_options, filename=filename) return module
def annotate(source, file_name): source = textwrap.dedent(source.lstrip('\n')) ast_factory = lambda unused_options: ast # pytype_options = config.Options.create(python_version=(3,7),nofail=True,protocols=True,no_report_errors=True,keep_going=True, # imports_map=pytype_out_path+'/imports/'+file_name) pytype_options = config.Options.create(python_version=(3, 7), nofail=True, protocols=True, imports_map=pytype_out_path + '/imports/' + file_name) module = annotate_ast.annotate_source(source, ast_factory, pytype_options) return module
SOURCE = """ #import math def f(a: float) -> float: b = 1 return a def add(a: int, b: int, tt: Tensor[int, L[20,20]]) -> int: uu = tt[0,0] e = f(6.1) + 1 g = math.sqrt(5.1) for i in range(0,10): v = 1 + i #c = a + 1 + 5 #if True: # c = c + 5 #r = 5 #c = 1 + 1.1 return a """ if __name__ == "__main__": root = ast3.parse(SOURCE) options = config.Options.create(python_version=(3, 7)) ast_factory = lambda unused_options: ast3 module = annotate_ast.annotate_source(SOURCE, ast_factory, options) print(ast3.dump(root)) visitor = Expr() visitor.visit(module) print(str(visitor.module)) visitor.module.compile() print(visitor.module.get_ir())
class Int: def __init__(self, val: int): self.val: int = val def add(a: int, b: int, c: Gen[int, Literal[2], Literal[(1, 2)]]): rr = a return a + b + 2 src = inspect.getsource(add) sig = inspect.signature(add) v = inspect.getclosurevars(add) #print(v) #print(src) #print(sig.parameters) source = """ class Gen(Generic[A,C]): def __init__(self): pass L = Literal g = Gen[int,L[1,2]]() """ root = ast3.parse(src) options = config.Options.create(python_version=(3, 7)) ast_factory = lambda unused_options: ast3 module2 = annotate_ast.annotate_source(source, ast_factory, options) #print(ast3.dump(root)) print(debug.dump(module2, ast3)) print(module2.body[2].targets[0].__dict__)