Feat(tools): Make 2 methods to explain capacities of compute and typing

This commit is contained in:
Bertrand Benjamin 2018-10-01 08:54:15 +02:00
parent f3f93d31a7
commit ddab3cebad
2 changed files with 25 additions and 10 deletions

View File

@ -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
# -----------------------------

View File

@ -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
# -----------------------------