allow no Explicable in merge_history and improve doctest
This commit is contained in:
		| @@ -125,6 +125,8 @@ class Explicable(Renderable): | ||||
|     def merge_history(expl1, expl2, operation): | ||||
|         r""" Take two Explicable objects, explain where they are from and merge their history | ||||
|  | ||||
|         This method try to use 'explain' method from expl1 and expl2. This means that after using this method, those two objects will become amnesiac. | ||||
|  | ||||
|         :param expl1: fist explicable | ||||
|         :param expl2: second explicable | ||||
|         :param operation: the operation that link them | ||||
| @@ -146,11 +148,30 @@ class Explicable(Renderable): | ||||
|         ['2 + 10 \\times 4', '2 \\times 12', +] | ||||
|         ['2 + 40', '24', +] | ||||
|         ['42', '24', +] | ||||
|         >>> for i in action1.explain(): | ||||
|         ...    print(i) | ||||
|  | ||||
|         >>> action1 = Explicable() | ||||
|         >>> action1.postfix_tokens = Expression('42') | ||||
|         >>> action1.this_append_before([Expression('2+10*4'), Expression('2+40')]) | ||||
|         >>> m_history = Explicable().merge_history(action1, 12, op.add) | ||||
|         >>> m_history | ||||
|         <generator object transpose_fill ...> | ||||
|         >>> for i in m_history: | ||||
|         ...    print(i) | ||||
|         ['2 + 10 \\times 4', 12, +] | ||||
|         ['2 + 40', 12, +] | ||||
|         ['42', 12, +] | ||||
|         """ | ||||
|         steps1 = list(expl1.explain()) | ||||
|         steps2 = list(expl2.explain()) | ||||
|         try: | ||||
|             steps1 = list(expl1.explain()) | ||||
|         except AttributeError: | ||||
|             steps1 = [expl1] | ||||
|  | ||||
|         try: | ||||
|             steps2 = list(expl2.explain()) | ||||
|         except AttributeError: | ||||
|             steps2 = [expl2] | ||||
|         return transpose_fill([steps1, steps2, [operation]]) | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user