From e6b715fc4e0bf6afc653240c2051d97e517ab558 Mon Sep 17 00:00:00 2001 From: Marion Date: Fri, 16 Aug 2013 13:43:02 +0000 Subject: convert Call ASTs to numbers by wrapping float(...) around them --- 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: -- cgit v0.9.1