diff options
author | Marion <marion.zepf@gmail.com> | 2013-10-08 15:29:07 (GMT) |
---|---|---|
committer | Marion <marion.zepf@gmail.com> | 2013-10-08 15:29:07 (GMT) |
commit | f14dd377dd0de86845fcf7ccb789f243366d2360 (patch) | |
tree | d1212b174890af3ae935c770a689fdde281b5248 | |
parent | 1cc929cd824a0629ce952ea26a2d0da79c2f725c (diff) |
turn an error during type conversion into a TATypeErrortype-system
- This makes it try the next type/ slot/ ...
-rw-r--r-- | TurtleArt/tatype.py | 29 |
1 files changed, 17 insertions, 12 deletions
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 |