From dfebf0be36908618c3b23839557dea93810b1198 Mon Sep 17 00:00:00 2001 From: Marion Date: Sun, 08 Sep 2013 14:12:50 +0000 Subject: Primitives for all constant blocks (add screen dimensions, update colors) - Use the get() method of the CONSTANTS dict to retrieve the values of constants, but export it as CONSTANTS['key']. - Introduce the new class TypedSubscript for Subscript ASTs with a type. --- (limited to 'TurtleArt/tatype.py') diff --git a/TurtleArt/tatype.py b/TurtleArt/tatype.py index 752f71b..9a8c17d 100644 --- a/TurtleArt/tatype.py +++ b/TurtleArt/tatype.py @@ -350,7 +350,17 @@ def convert(x, new_type, old_type=None, converter=None): return _apply_converter(converter, x) -class TypedCall(ast.Call): +class TypedAST(ast.AST): + + @property + def return_type(self): + if self._return_type is None: + return get_type(self.func)[0] + else: + return self._return_type + + +class TypedCall(ast.Call,TypedAST): """ Like a Call AST, but with a return type """ def __init__(self, func, args=None, keywords=None, starargs=None, @@ -366,12 +376,15 @@ class TypedCall(ast.Call): self._return_type = return_type - @property - def return_type(self): - if self._return_type is None: - return get_type(self.func)[0] - else: - return self._return_type + +class TypedSubscript(ast.Subscript,TypedAST): + """ Like a Subscript AST, but with a return type """ + + def __init__(self, value, slice_, ctx=ast.Load, return_type=None): + + ast.Subscript.__init__(self, value=value, slice=slice_, ctx=ctx) + + self._return_type = return_type def get_call_ast(func_name, args=None, kwargs=None, return_type=None): -- cgit v0.9.1