Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarion <marion.zepf@gmail.com>2013-10-08 15:00:14 (GMT)
committer Marion <marion.zepf@gmail.com>2013-10-08 15:00:14 (GMT)
commit1cc929cd824a0629ce952ea26a2d0da79c2f725c (patch)
tree128d0dbeb1acc31be34550d7ae1ff972bd4952ed
parentfd45a42ac1a909023e63d4dfa35419fdae5df9f6 (diff)
always accept lambda functions as arguments (even though their type is unknown)
- more debugging output on TATypeErrors in Primitive
-rw-r--r--TurtleArt/taprimitive.py57
1 files changed, 36 insertions, 21 deletions
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py
index e5266a1..112540a 100644
--- a/TurtleArt/taprimitive.py
+++ b/TurtleArt/taprimitive.py
@@ -22,6 +22,7 @@ import ast
from gettext import gettext as _
from math import sqrt
from random import uniform
+import traceback
#from ast_pprint import * # only used for debugging, safe to comment out
@@ -184,6 +185,8 @@ class Primitive(object):
convert_to_ast=convert_to_ast,
call_my_args=call_my_args)
except TATypeError as error:
+ if Primitive._DEBUG:
+ traceback.print_exc()
break
else:
new_slot_list.append(const)
@@ -875,30 +878,38 @@ class ArgSlot(object):
for wrapper in wrapper_disjunction:
# check if the argument can fill this slot (type-wise)
- if wrapper is not None:
- arg_types = get_type(wrapper)[0]
- bad_value = wrapper
- elif func is not None:
- arg_types = get_type(func)[0]
- bad_value = func
- else:
- arg_types = get_type(argument)[0]
- bad_value = argument
- converter = None
- if not isinstance(arg_types, TypeDisjunction):
- arg_types = TypeDisjunction((arg_types, ))
- if isinstance(slot.type, TypeDisjunction):
- slot_types = slot.type
+ # (lambda functions are always accepted)
+ if getattr(func, '__name__', None) == '<lambda>':
+ converter = identity
+ old_type = TYPE_OBJECT
+ new_type = slot.type
else:
- slot_types = TypeDisjunction((slot.type, ))
- for old_type in arg_types:
- for new_type in slot_types:
- converter = get_converter(old_type, new_type)
+ if wrapper is not None:
+ arg_types = get_type(wrapper)[0]
+ bad_value = wrapper
+ elif func is not None:
+ arg_types = get_type(func)[0]
+ bad_value = func
+ else:
+ arg_types = get_type(argument)[0]
+ bad_value = argument
+ converter = None
+ if not isinstance(arg_types, TypeDisjunction):
+ arg_types = TypeDisjunction((arg_types, ))
+ if isinstance(slot.type, TypeDisjunction):
+ slot_types = slot.type
+ else:
+ slot_types = TypeDisjunction((slot.type, ))
+ for old_type in arg_types:
+ for new_type in slot_types:
+ converter = get_converter(old_type, new_type)
+ if converter is not None:
+ break
if converter is not None:
break
- # unable to convert, try next wrapper/ slot/ func
- if converter is None:
- continue
+ # unable to convert, try next wrapper/ slot/ func
+ if converter is None:
+ continue
# 1. (cont'd) call the argument or pass it on as a callable
called_argument = argument
@@ -912,6 +923,8 @@ class ArgSlot(object):
convert_to_ast=convert_to_ast,
call_my_args=(slot.call_arg and call_my_args))
except TATypeError as error:
+ if Primitive._DEBUG:
+ traceback.print_exc()
# on failure, try next wrapper/ slot/ func
bad_value = error.bad_value
continue
@@ -958,6 +971,8 @@ class ArgSlot(object):
new_type, old_type=old_type,
converter=converter)
except TATypeError as error:
+ if Primitive._DEBUG:
+ traceback.print_exc()
# on failure, try next wrapper/ slot/ func
bad_value = wrapped_argument
continue