diff options
author | Marion <marion.zepf@gmail.com> | 2013-09-08 22:28:30 (GMT) |
---|---|---|
committer | Marion <marion.zepf@gmail.com> | 2013-09-08 22:28:30 (GMT) |
commit | 80ea36e20b39af16ea4032cb3683db5412f47f0e (patch) | |
tree | 2392686ac4bdac8e4389820f7976f7a925aeea1e | |
parent | 69cbd8c2f35c96f9e22917546a5ecc82a83b98e2 (diff) |
clean up taprimitive: remove unused stuff, add documentation
-rw-r--r-- | TurtleArt/taprimitive.py | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py index f969e96..70762f1 100644 --- a/TurtleArt/taprimitive.py +++ b/TurtleArt/taprimitive.py @@ -65,7 +65,6 @@ class Primitive(object): 'divide': ast.Div, 'modulo': ast.Mod, 'power': ast.Pow, - 'integer_division': ast.FloorDiv, 'and_': ast.And, 'or_': ast.Or, 'not_': ast.Not, @@ -74,21 +73,15 @@ class Primitive(object): 'greater': ast.Gt} def __init__(self, func, return_type=TYPE_OBJECT, arg_descs=None, kwarg_descs=None, - call_afterwards=None, export_me=True, - # deprecated: - call_me=True, slot_wrappers=None, constant_args=None): + call_afterwards=None, export_me=True): """ return_type -- the type (from the type hierarchy) that this Primitive will return - # TODO make mandatory! arg_descs, kwarg_descs -- a list of argument descriptions and a dictionary of keyword argument descriptions. An argument description can be either an ArgSlot or a ConstantArg. call_afterwards -- Code to call after this Primitive has been called (e.g., for updating labels in LogoCode) (not used for creating AST) - call_me -- True if this Primitive should be called (default), False - if it should be passed on as a Primitive object - # TODO obsolete ??? export_me -- True iff this Primitive should be exported to Python code (the default case) """ self.func = func @@ -105,7 +98,6 @@ class Primitive(object): self.kwarg_descs = kwarg_descs self.call_afterwards = call_afterwards - self.call_me = call_me self.export_me = export_me def copy(self): @@ -119,7 +111,6 @@ class Primitive(object): arg_descs=arg_descs_copy, kwarg_descs=self.kwarg_descs.copy(), call_afterwards=self.call_afterwards, - call_me=self.call_me, export_me=self.export_me) def __repr__(self): @@ -486,8 +477,9 @@ class Primitive(object): # other is a Primitive if isinstance(other, Primitive): return (self == other.func and - self.constant_args == other.constant_args and - self.slot_wrappers == other.slot_wrappers and + self.return_type == other.return_type and + self.arg_descs == other.arg_descs and + self.kwarg_descs == other.kwarg_descs and self.call_afterwards == other.call_afterwards and self.export_me == other.export_me) @@ -495,7 +487,7 @@ class Primitive(object): elif callable(other): if is_instancemethod(self.func) != is_instancemethod(other): return False - elif is_instancemethod(self.func): # and is_instancemethod(other): + elif is_instancemethod(self.func): # and is_instancemethod(other): return (self.func.im_class == other.im_class and self.func.im_func == other.im_func) else: @@ -668,18 +660,13 @@ class Primitive(object): @staticmethod def square_root(arg1): - """ Raise the first argument to the power given by the second """ + """ Return the square root of the argument. If it is a negative + number, raise a NegativeRootError. """ if arg1 < 0: raise NegativeRootError(neg_value=arg1) return sqrt(arg1) @staticmethod - def integer_division(arg1, arg2): - """ Divide the first argument by the second and return the integer - that is smaller than or equal to the result """ - return arg1 // arg2 - - @staticmethod def and_(arg1, arg2): """ Logcially conjoin the two arguments (using short-circuting) """ return arg1 and arg2 @@ -760,7 +747,10 @@ class PrimitiveDisjunction(Disjunction,Primitive): return TypeDisjunction((prim.return_type for prim in self)) def __call__(self, *runtime_args, **runtime_kwargs): - """ TODO doc """ + """ Loop over the disjunct Primitives and try to fill their slots + with the given args and kwargs. Call the first Primitives whose + slots could be filled successfully. If all disjunct Primitives + fail, raise the last error that occurred. """ # remove the first argument if it is a LogoCode instance if runtime_args and isinstance(runtime_args[0], LogoCode): |