diff options
author | Marion <marion.zepf@gmail.com> | 2013-08-31 20:41:05 (GMT) |
---|---|---|
committer | Marion <marion.zepf@gmail.com> | 2013-08-31 20:41:05 (GMT) |
commit | 5052f0e75b77c279484a74393f4ff6c55a07af7d (patch) | |
tree | f710cc4870a27c4a4131459a9733d1a966d07d46 /TurtleArt | |
parent | b824b27903c7fb01e1880551a0d8ed1eea187bf4 (diff) |
fix export of keyword arguments to Primitives
Diffstat (limited to 'TurtleArt')
-rw-r--r-- | TurtleArt/taprimitive.py | 15 | ||||
-rw-r--r-- | TurtleArt/tatype.py | 10 |
2 files changed, 14 insertions, 11 deletions
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py index e09963b..2abfd78 100644 --- a/TurtleArt/taprimitive.py +++ b/TurtleArt/taprimitive.py @@ -58,7 +58,7 @@ class Primitive(object): but that can also be transformed into a Python AST. """ - _DEBUG = True + _DEBUG = False STANDARD_OPERATORS = {'plus': (ast.UAdd, ast.Add), 'minus': (ast.USub, ast.Sub), @@ -1104,18 +1104,19 @@ class ConstantArg(object): self.call_arg = call_arg def get(self, convert_to_ast=False): - """ If call_arg is False or the value is not callable, return the - value as is. If call_arg is True and convert_to_ast is False, call - the value and return its return value. If call_arg and - convert_to_ast are both True, convert the value to an AST and - return that. """ + """ If call_arg is True and the value is callable, call the value + and return its return value. Else, return the value unchanged. + convert_to_ast -- return the equivalent AST instead of a raw value """ if self.call_arg and callable(self.value): if convert_to_ast: return value_to_ast(self.value) else: return self.value() else: - return self.value + if convert_to_ast and not isinstance(self.value, list): + return value_to_ast(self.value) + else: + return self.value def __repr__(self): return "ConstantArg(%s)" % (repr(self.value)) diff --git a/TurtleArt/tatype.py b/TurtleArt/tatype.py index 477e028..3fa7a83 100644 --- a/TurtleArt/tatype.py +++ b/TurtleArt/tatype.py @@ -178,14 +178,16 @@ TYPE_CONVERTERS = { } -def get_call_ast(func_name, args=None, keywords=None): +def get_call_ast(func_name, args=None, kwargs=None): """ Return an AST representing the call to a function with the name func_name, passing it the arguments args (given as a list) and the - keyword arguments keywords (given as a dictionary). """ + keyword arguments kwargs (given as a dictionary). """ if args is None: args = [] - if keywords is None: - keywords = {} + keywords = [] + if kwargs is not None: + for (key, value) in kwargs.iteritems(): + keywords.append(ast.keyword(arg=key, value=value)) return ast.Call(func=ast.Name(id=func_name, ctx=ast.Load), args=args, |