diff options
author | Marion <marion.zepf@gmail.com> | 2013-08-16 13:43:02 (GMT) |
---|---|---|
committer | Marion <marion.zepf@gmail.com> | 2013-08-16 13:43:02 (GMT) |
commit | e6b715fc4e0bf6afc653240c2051d97e517ab558 (patch) | |
tree | 52d88c43753bf0ac5c62abd3407bf68929e432b9 | |
parent | 0a6a3deb566df8c7832b6181d03db55039200976 (diff) |
convert Call ASTs to numbers by wrapping float(...) around them
-rw-r--r-- | TurtleArt/taprimitive.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py index 6f83294..5c44d63 100644 --- a/TurtleArt/taprimitive.py +++ b/TurtleArt/taprimitive.py @@ -675,7 +675,9 @@ class Primitive(object): 3. Convert a single character to its ASCII integer value. 4. Extract the first element of a list and convert it to a number. 5. Convert a Color to a float. - Return None if the value cannot be converted to a number. """ + If the value cannot be converted to a number and the value is not + an AST, return None. If it is an AST, return an AST representing + `float(value)'. """ # TODO find a better solution # 1. number if isinstance(value, (float, int, long, ast.Num)): return value @@ -696,11 +698,11 @@ class Primitive(object): conversion_ast = Primitive.convert_for_cmp(value_ast, decimal_point) if not isinstance(conversion_ast, ast.Num): - return None + converted = None else: converted = Primitive.convert_for_cmp(value, decimal_point) if not isinstance(converted, (float, int, long)): - return None + converted = None # 4. list elif isinstance(value, list): if value: @@ -710,14 +712,18 @@ class Primitive(object): else: converted = number else: - return None + converted = None + if convert_to_ast: + conversion_ast = get_call_ast('float', [value_ast]) # 5. Color elif isinstance(value, Color): converted = float(value) if convert_to_ast: conversion_ast = get_call_ast('float', [value_ast]) else: - return None + converted = None + if convert_to_ast: + conversion_ast = get_call_ast('float', [value_ast]) if convert_to_ast: if conversion_ast is None: |