Fix(steps): Typing steps are bypassed
Useless steps where complex objects were built are not shown. I create a typing function which is called when compute raise NotImplementedError.
This commit is contained in:
44
mapytex/calculus/core/typing/__init__.py
Normal file
44
mapytex/calculus/core/typing/__init__.py
Normal file
@@ -0,0 +1,44 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2017 lafrite <lafrite@Poivre>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
|
||||
"""
|
||||
Computing with MO
|
||||
"""
|
||||
|
||||
from .exceptions import TypingError
|
||||
# from .add import add
|
||||
# from .minus import minus
|
||||
# from .multiply import multiply
|
||||
from .divide import divide
|
||||
|
||||
OPERATIONS = {
|
||||
# "+": add,
|
||||
# "-": minus,
|
||||
# "*": multiply,
|
||||
"/": divide,
|
||||
}
|
||||
|
||||
def typing(node, left_v, right_v):
|
||||
"""
|
||||
Typing a try base on his root node
|
||||
|
||||
:example:
|
||||
|
||||
>>> from ..MO.mo import MOnumber
|
||||
"""
|
||||
try:
|
||||
operation = OPERATIONS[node]
|
||||
except KeyError:
|
||||
raise TypingError(f"Unknown operation ({node})")
|
||||
return operation(left_v, right_v)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
43
mapytex/calculus/core/typing/divide.py
Normal file
43
mapytex/calculus/core/typing/divide.py
Normal file
@@ -0,0 +1,43 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2017 lafrite <lafrite@Poivre>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
|
||||
"""
|
||||
Typing trees with a divide root
|
||||
"""
|
||||
|
||||
from multipledispatch import Dispatcher
|
||||
from ..MO.mo import MO, MOnumber
|
||||
from ..MO.fraction import MOFraction
|
||||
|
||||
divide_doc = """ Typing trees a divide root
|
||||
|
||||
:param left: left MO
|
||||
:param right: right MO
|
||||
:returns: Tree or MO
|
||||
|
||||
"""
|
||||
|
||||
divide = Dispatcher("divide", doc=divide_doc)
|
||||
|
||||
@divide.register(MOnumber, MOnumber)
|
||||
def monumber_monumber(left, right):
|
||||
""" A divide tree with 2 MOnumbers is a MOFraction
|
||||
|
||||
>>> a = MOnumber(4)
|
||||
>>> b = MOnumber(6)
|
||||
>>> monumber_monumber(a, b)
|
||||
<MOFraction 4 / 6>
|
||||
|
||||
"""
|
||||
return MOFraction(left, right)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
19
mapytex/calculus/core/typing/exceptions.py
Normal file
19
mapytex/calculus/core/typing/exceptions.py
Normal file
@@ -0,0 +1,19 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2017 lafrite <lafrite@Poivre>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
|
||||
"""
|
||||
Exceptions for typing trees
|
||||
"""
|
||||
|
||||
class TypingError(Exception):
|
||||
pass
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
Reference in New Issue
Block a user