From ddab3cebadbce504cfe38be2f4c73b052a7fefcc Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Mon, 1 Oct 2018 08:54:15 +0200 Subject: [PATCH] Feat(tools): Make 2 methods to explain capacities of compute and typing --- mapytex/calculus/core/compute/__init__.py | 10 ++++++--- mapytex/calculus/core/typing/__init__.py | 25 ++++++++++++++++------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/mapytex/calculus/core/compute/__init__.py b/mapytex/calculus/core/compute/__init__.py index 093bf9c..3ea9ff6 100644 --- a/mapytex/calculus/core/compute/__init__.py +++ b/mapytex/calculus/core/compute/__init__.py @@ -77,10 +77,14 @@ def compute_capacities(node): ) return lines +def describe_compute(): + """ Explain which operation are handle by compue """ -compute.__doc__ += "Implemented compute operations among MOs" -for op in OPERATIONS: - compute.__doc__ += f"\n{tabulate(compute_capacities(op), tablefmt='grid')} \n" + ans = "Implemented compute operations among MOs" + for op in OPERATIONS: + ans += "\n" + ans += tabulate(compute_capacities(op), tablefmt='grid') + return ans # ----------------------------- diff --git a/mapytex/calculus/core/typing/__init__.py b/mapytex/calculus/core/typing/__init__.py index 1845502..babc408 100644 --- a/mapytex/calculus/core/typing/__init__.py +++ b/mapytex/calculus/core/typing/__init__.py @@ -16,6 +16,15 @@ from .exceptions import TypingError # from .multiply import multiply from .divide import divide +from ..MO.mo import MOnumber, MOstr +from ..MO.fraction import MOFraction +from ..MO.monomial import MOstrPower, MOMonomial + +from itertools import product +from tabulate import tabulate + +MOS = [ MOnumber, MOstr, MOFraction, MOstrPower, MOMonomial ] + OPERATIONS = { # "+": add, # "-": minus, @@ -43,10 +52,6 @@ def typing_capacities(node): :param operation: string which represent an (mo, mo) -> mo :returns: { (motype, motype): True/False } when it's implemented - :example: - >>> typing_capacities("+") - [['+', 'MOnumber', 'MOstr', 'MOFraction', 'MOstrPower', 'MOMonomial'], ['MOnumber', True, False, True, False, False], ['MOstr', False, False, False, False, False], ['MOFraction', True, False, True, False, False], ['MOstrPower', False, False, False, False, False], ['MOMonomial', False, False, False, False, False]] - """ op = OPERATIONS[node] lines = [[node] + [mo.__name__ for mo in MOS]] @@ -57,9 +62,15 @@ def typing_capacities(node): ) return lines -typing.__doc__ += "Implemented typing operations among MOs" -for op in OPERATIONS: - typing.__doc__ += f"\n{tabulate(typing_capacities(op), tablefmt='grid')} \n" +def describe_typing(): + """ Explain which operations are handle by typing """ + + ans = "Implemented typing operations among MOs\n" + for op in OPERATIONS: + ans += "\n" + ans += tabulate(typing_capacities(op), tablefmt='grid') + + return ans # -----------------------------