new initiat for Renderable and Explicable - need to fix other
This commit is contained in:
parent
351a9002be
commit
e34215a9a9
@ -16,8 +16,8 @@ class Explicable(Renderable):
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Explicable, self).__init__()
|
||||
def __init__(self, pstf_tokens):
|
||||
super(Explicable, self).__init__(pstf_tokens)
|
||||
self.steps = []
|
||||
self.explained = 0
|
||||
|
||||
@ -27,9 +27,8 @@ class Explicable(Renderable):
|
||||
After beening explained, the Explicable become amnesiac. It will return itself in a list.
|
||||
See 'history_generator' to explain it once again.
|
||||
|
||||
>>> action = Explicable()
|
||||
>>> action = Explicable(['42'])
|
||||
>>> from .expression import Expression
|
||||
>>> action.postfix_tokens = Expression('42')
|
||||
>>> action.this_append_before([Expression('2+10*4'), Expression('2+40')])
|
||||
>>> for i in action.explain():
|
||||
... print(i)
|
||||
@ -40,8 +39,7 @@ class Explicable(Renderable):
|
||||
>>> for i in action.explain():
|
||||
... print(i)
|
||||
42
|
||||
>>> action = Explicable()
|
||||
>>> action.postfix_tokens = Expression('42')
|
||||
>>> action = Explicable(['42'])
|
||||
>>> for i in action.explain():
|
||||
... print(i)
|
||||
42
|
||||
@ -59,9 +57,8 @@ class Explicable(Renderable):
|
||||
This is the called method in explain which create the generator.
|
||||
It create a new generator at each call.
|
||||
|
||||
>>> action = Explicable()
|
||||
>>> action = Explicable(['42'])
|
||||
>>> from .expression import Expression
|
||||
>>> action.postfix_tokens = Expression('42')
|
||||
>>> for i in action.history_generator():
|
||||
... print(i)
|
||||
42
|
||||
@ -116,7 +113,7 @@ class Explicable(Renderable):
|
||||
|
||||
:param steps: list of steps that append before
|
||||
|
||||
>>> e = Explicable()
|
||||
>>> e = Explicable(['Actions'])
|
||||
>>> s = ['eat', 'sleep']
|
||||
>>> e.this_append_before(s)
|
||||
>>> print(e.steps)
|
||||
@ -139,9 +136,8 @@ class Explicable(Renderable):
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
|
||||
@staticmethod
|
||||
def merge_history(explicables):
|
||||
@classmethod
|
||||
def merge_history(cls, explicables):
|
||||
r""" Take a list of Explicable objects, explain where they are from and merge their history
|
||||
|
||||
This method try to use 'explain' method from Explicable. This means that after using this method, those objects will become amnesiac.
|
||||
@ -150,13 +146,11 @@ class Explicable(Renderable):
|
||||
:returns: the list of steps
|
||||
|
||||
>>> from .expression import Expression
|
||||
>>> action1 = Explicable()
|
||||
>>> action1.postfix_tokens = Expression('42')
|
||||
>>> action1 = Explicable(['42'])
|
||||
>>> action1.this_append_before([Expression('2+10*4'), Expression('2+40')])
|
||||
>>> action2 = Explicable()
|
||||
>>> action2.postfix_tokens = Expression('24')
|
||||
>>> action2 = Explicable(['24'])
|
||||
>>> action2.this_append_before([Expression('2*12')])
|
||||
>>> m_history = Explicable().merge_history([action1, action2])
|
||||
>>> m_history = Explicable.merge_history([action1, action2])
|
||||
>>> m_history
|
||||
<generator object transpose_fill ...>
|
||||
>>> for i in m_history:
|
||||
@ -168,14 +162,13 @@ class Explicable(Renderable):
|
||||
>>> for i in action1.explain():
|
||||
... print(i)
|
||||
42
|
||||
>>> m_history = Explicable().merge_history([action1, action2])
|
||||
>>> m_history = Explicable.merge_history([action1, action2])
|
||||
>>> for i in m_history:
|
||||
... print(i)
|
||||
['42', '24']
|
||||
>>> action1 = Explicable()
|
||||
>>> action1.postfix_tokens = Expression('42')
|
||||
>>> action1 = Explicable(['42'])
|
||||
>>> action1.this_append_before([Expression('2+10*4'), Expression('2+40')])
|
||||
>>> m_history = Explicable().merge_history([action1, 12])
|
||||
>>> m_history = Explicable.merge_history([action1, 12])
|
||||
>>> m_history
|
||||
<generator object transpose_fill ...>
|
||||
>>> for i in m_history:
|
||||
@ -183,22 +176,19 @@ class Explicable(Renderable):
|
||||
['2 + 10 \\times 4', 12]
|
||||
['2 + 40', 12]
|
||||
['42', 12]
|
||||
>>> action1 = Explicable()
|
||||
>>> action1.postfix_tokens = Expression('42')
|
||||
>>> action1 = Explicable(['42'])
|
||||
>>> action1.this_append_before([Expression('2+10*4'), Expression('2+40')])
|
||||
>>> action2 = Explicable()
|
||||
>>> action2.postfix_tokens = Expression('24')
|
||||
>>> action2 = Explicable(['24'])
|
||||
>>> action2.this_append_before([Expression('2*12')])
|
||||
>>> action3 = Explicable()
|
||||
>>> action3.postfix_tokens = Expression('0')
|
||||
>>> action3 = Explicable(['0'])
|
||||
>>> action3.this_append_before([Expression('3-3')])
|
||||
>>> m_history = Explicable().merge_history([action1, action2, action3])
|
||||
>>> m_history = Explicable.merge_history([action1, action2, action3])
|
||||
>>> for i in m_history:
|
||||
... print(i)
|
||||
['2 + 10 \\times 4', '2 \\times 12', '3 - 3']
|
||||
['2 + 40', '24', '0']
|
||||
['42', '24', '0']
|
||||
>>> m_history = Explicable().merge_history([1,2,3])
|
||||
>>> m_history = Explicable.merge_history([1,2,3])
|
||||
>>> for i in m_history:
|
||||
... print(i)
|
||||
[1, 2, 3]
|
||||
|
@ -139,6 +139,14 @@ class Renderable(object):
|
||||
Renderable.set_render(self.old_render)
|
||||
return TmpRenderEnv()
|
||||
|
||||
def __init__(self, pstf_tokens):
|
||||
"""Initiate the renderable objet
|
||||
|
||||
:param pstf_tokens: the postfix list of tokens
|
||||
|
||||
"""
|
||||
self.postfix_tokens = pstf_tokens
|
||||
|
||||
def __repr__(self):
|
||||
return "< {cls} {pstf_tokens}>".format(
|
||||
cls = str(self.__class__).split('.')[-1][:-2],
|
||||
|
Loading…
Reference in New Issue
Block a user