From 9e64f7dc3ae5c4a223e732e5987ea065a5f539f8 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 12 Oct 2015 14:45:11 +0300 Subject: [PATCH] Adapt old compiler to Python 3.5 AST. --- artiq/transforms/inline.py | 6 ++---- artiq/transforms/interleave.py | 3 +-- artiq/transforms/lower_time.py | 6 ++---- artiq/transforms/quantize_time.py | 12 ++++------- artiq/transforms/tools.py | 6 ++---- artiq/transforms/unparse.py | 35 +++++-------------------------- 6 files changed, 16 insertions(+), 52 deletions(-) diff --git a/artiq/transforms/inline.py b/artiq/transforms/inline.py index dd67e0c69..4d444bbe8 100644 --- a/artiq/transforms/inline.py +++ b/artiq/transforms/inline.py @@ -356,8 +356,7 @@ class Function: exception_id = self.mappers.exception.encode(exception_class) return ast.copy_location( ast.Call(func=ast.Name("EncodedException", ast.Load()), - args=[value_to_ast(exception_id)], - keywords=[], starargs=None, kwargs=None), + args=[value_to_ast(exception_id)], keywords=[]), e) def code_visit_Raise(self, node): @@ -514,8 +513,7 @@ def get_attr_writeback(attribute_namespace, rpc_mapper, loc_node): arg3 = ast.copy_location( ast.Name(attr_info.mangled_name, ast.Load()), loc_node) call = ast.copy_location( - ast.Call(func=func, args=[arg1, arg2, arg3], - keywords=[], starargs=None, kwargs=None), + ast.Call(func=func, args=[arg1, arg2, arg3], keywords=[]), loc_node) expr = ast.copy_location(ast.Expr(call), loc_node) attr_writeback.append(expr) diff --git a/artiq/transforms/interleave.py b/artiq/transforms/interleave.py index 8aa9df838..7d1f733ff 100644 --- a/artiq/transforms/interleave.py +++ b/artiq/transforms/interleave.py @@ -71,8 +71,7 @@ def _interleave_timelines(timelines): delay_stmt = ast.copy_location( ast.Expr(ast.Call( func=ast.Name("delay_mu", ast.Load()), - args=[value_to_ast(dt)], - keywords=[], starargs=[], kwargs=[])), + args=[value_to_ast(dt)], keywords=[])), ref_stmt) r.append(delay_stmt) else: diff --git a/artiq/transforms/lower_time.py b/artiq/transforms/lower_time.py index 5b3df0245..904d73834 100644 --- a/artiq/transforms/lower_time.py +++ b/artiq/transforms/lower_time.py @@ -46,14 +46,12 @@ def lower_time(func_def): _TimeLowerer().visit(func_def) call_init = ast.Call( func=ast.Name("syscall", ast.Load()), - args=[ast.Str("now_init")], - keywords=[], starargs=None, kwargs=None) + args=[ast.Str("now_init")], keywords=[]) stmt_init = ast.Assign(targets=[ast.Name("now", ast.Store())], value=call_init) call_save = ast.Call( func=ast.Name("syscall", ast.Load()), - args=[ast.Str("now_save"), ast.Name("now", ast.Load())], - keywords=[], starargs=None, kwargs=None) + args=[ast.Str("now_save"), ast.Name("now", ast.Load())], keywords=[]) stmt_save = ast.Expr(call_save) func_def.body = [ stmt_init, diff --git a/artiq/transforms/quantize_time.py b/artiq/transforms/quantize_time.py index aad75069a..e4125d624 100644 --- a/artiq/transforms/quantize_time.py +++ b/artiq/transforms/quantize_time.py @@ -23,8 +23,7 @@ def _seconds_to_mu(ref_period, node): node) return ast.copy_location( ast.Call(func=ast.Name("round64", ast.Load()), - args=[divided], - keywords=[], starargs=[], kwargs=[]), + args=[divided], keywords=[]), divided) @@ -77,12 +76,10 @@ class _TimeQuantizer(ast.NodeTransformer): right=ast.Num(1000)) time_int = ast.Call( func=ast.Name("round", ast.Load()), - args=[time], - keywords=[], starargs=None, kwargs=None) + args=[time], keywords=[]) syscall_set = ast.Call( func=ast.Name("syscall", ast.Load()), - args=[ast.Str("watchdog_set"), time_int], - keywords=[], starargs=None, kwargs=None) + args=[ast.Str("watchdog_set"), time_int], keywords=[]) stmt_set = ast.copy_location( ast.Assign(targets=[ast.Name(idname, ast.Store())], value=syscall_set), @@ -91,8 +88,7 @@ class _TimeQuantizer(ast.NodeTransformer): syscall_clear = ast.Call( func=ast.Name("syscall", ast.Load()), args=[ast.Str("watchdog_clear"), - ast.Name(idname, ast.Load())], - keywords=[], starargs=None, kwargs=None) + ast.Name(idname, ast.Load())], keywords=[]) stmt_clear = ast.copy_location(ast.Expr(syscall_clear), node) node.items[0] = ast.withitem( diff --git a/artiq/transforms/tools.py b/artiq/transforms/tools.py index 97d596d2b..557a60221 100644 --- a/artiq/transforms/tools.py +++ b/artiq/transforms/tools.py @@ -40,8 +40,7 @@ def value_to_ast(value): if isinstance(value, core_language.int64): # must be before int return ast.Call( func=ast.Name("int64", ast.Load()), - args=[ast.Num(int(value))], - keywords=[], starargs=None, kwargs=None) + args=[ast.Num(int(value))], keywords=[]) elif isinstance(value, bool) or value is None: # must also be before int # isinstance(True/False, int) == True @@ -51,8 +50,7 @@ def value_to_ast(value): elif isinstance(value, Fraction): return ast.Call( func=ast.Name("Fraction", ast.Load()), - args=[ast.Num(value.numerator), ast.Num(value.denominator)], - keywords=[], starargs=None, kwargs=None) + args=[ast.Num(value.numerator), ast.Num(value.denominator)], keywords=[]) elif isinstance(value, str): return ast.Str(value) elif isinstance(value, list): diff --git a/artiq/transforms/unparse.py b/artiq/transforms/unparse.py index cacd6e73b..c796b58e8 100644 --- a/artiq/transforms/unparse.py +++ b/artiq/transforms/unparse.py @@ -211,20 +211,6 @@ class _Unparser: else: comma = True self.dispatch(e) - if t.starargs: - if comma: - self.write(", ") - else: - comma = True - self.write("*") - self.dispatch(t.starargs) - if t.kwargs: - if comma: - self.write(", ") - else: - comma = True - self.write("**") - self.dispatch(t.kwargs) self.write(")") self.enter() @@ -466,20 +452,6 @@ class _Unparser: else: comma = True self.dispatch(e) - if t.starargs: - if comma: - self.write(", ") - else: - comma = True - self.write("*") - self.dispatch(t.starargs) - if t.kwargs: - if comma: - self.write(", ") - else: - comma = True - self.write("**") - self.dispatch(t.kwargs) self.write(")") def _Subscript(self, t): @@ -571,8 +543,11 @@ class _Unparser: self.dispatch(t.kwarg.annotation) def _keyword(self, t): - self.write(t.arg) - self.write("=") + if t.arg is None: + self.write("**") + else: + self.write(t.arg) + self.write("=") self.dispatch(t.value) def _Lambda(self, t):