From f14dd377dd0de86845fcf7ccb789f243366d2360 Mon Sep 17 00:00:00 2001 From: Marion Date: Tue, 08 Oct 2013 15:29:07 +0000 Subject: turn an error during type conversion into a TATypeError - This makes it try the next type/ slot/ ... --- diff --git a/TurtleArt/tatype.py b/TurtleArt/tatype.py index 78cbcc3..359b5fc 100644 --- a/TurtleArt/tatype.py +++ b/TurtleArt/tatype.py @@ -336,19 +336,24 @@ def convert(x, new_type, old_type=None, converter=None): " for this type combination")) def _apply_converter(converter, y): - if is_an_ast: - if converter == identity: - return y - elif is_instancemethod(converter): - func = ast.Attribute(value=y, - attr=converter.im_func.__name__, - ctx=ast.Load) - return get_call_ast(func) + try: + if is_an_ast: + if converter == identity: + return y + elif is_instancemethod(converter): + func = ast.Attribute(value=y, + attr=converter.im_func.__name__, + ctx=ast.Load) + return get_call_ast(func) + else: + func_name = converter.__name__ + return get_call_ast(func_name, [y]) else: - func_name = converter.__name__ - return get_call_ast(func_name, [y]) - else: - return converter(y) + return converter(y) + except BaseException: + raise TATypeError(bad_value=x, bad_type=old_type, + req_type=new_type, message=("error during " + "conversion")) if isinstance(converter, (list, tuple)): # apply the converter chain recursively -- cgit v0.9.1