Some PEP8 rectifications
This commit is contained in:
parent
e9046c49ff
commit
e4efa1028e
@ -7,7 +7,7 @@
|
||||
# Distributed under terms of the MIT license.
|
||||
|
||||
from mapytex.calculus.core.tree import Tree
|
||||
from .mo import MO, MOError
|
||||
from .mo import MO
|
||||
|
||||
__all__ = ["MOFraction"]
|
||||
|
||||
|
@ -6,9 +6,9 @@
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
|
||||
from decimal import Decimal
|
||||
from ..coroutine import coroutine, STOOOP
|
||||
from ..renders import tree2txt, tree2tex
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
__all__ = ["moify", "MO", "MOstr"]
|
||||
@ -59,7 +59,6 @@ class MO(object):
|
||||
>>> a = MO(a)
|
||||
>>> a
|
||||
<MO 3>
|
||||
|
||||
"""
|
||||
try:
|
||||
self.value = value.value
|
||||
@ -107,7 +106,7 @@ class MOnumber(MO):
|
||||
|
||||
""" Base number math object (int or Decimal) """
|
||||
|
||||
def __init__(self, value, negative=False):
|
||||
def __init__(self, value):
|
||||
""" Initiate a number MO
|
||||
|
||||
>>> MOnumber(23)
|
||||
@ -134,7 +133,7 @@ class MOnumber(MO):
|
||||
except AttributeError:
|
||||
val = value
|
||||
|
||||
if isinstance(val, int) or isinstance(val, Decimal):
|
||||
if isinstance(val, (int, Decimal)):
|
||||
MO.__init__(self, value)
|
||||
elif isinstance(val, float):
|
||||
MO.__init__(self, Decimal(val))
|
||||
|
@ -10,7 +10,6 @@
|
||||
Computing with MO
|
||||
"""
|
||||
|
||||
from ..operator import OPERATORS
|
||||
from .exceptions import ComputeError
|
||||
from .add import add
|
||||
from .minus import minus
|
||||
|
@ -11,8 +11,7 @@ Adding MO
|
||||
"""
|
||||
|
||||
from ..tree import Tree
|
||||
from ..operator import OPERATORS
|
||||
from ..MO.mo import MO, MOnumber, MOstr
|
||||
from ..MO.mo import MO, MOnumber
|
||||
from ..MO.fraction import MOFraction
|
||||
from .exceptions import AddError
|
||||
from .arithmetic import lcm
|
||||
|
@ -22,6 +22,9 @@ class MinusError(ComputeError):
|
||||
class MultiplyError(ComputeError):
|
||||
pass
|
||||
|
||||
class DivideError(ComputeError):
|
||||
pass
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
|
@ -10,12 +10,9 @@
|
||||
Minus MO: take the opposit
|
||||
"""
|
||||
|
||||
from ..tree import Tree
|
||||
from ..operator import OPERATORS
|
||||
from ..MO.mo import MO, MOnumber, MOstr
|
||||
from ..MO.mo import MO, MOnumber
|
||||
from ..MO.fraction import MOFraction
|
||||
from .exceptions import MinusError
|
||||
from .arithmetic import lcm
|
||||
|
||||
|
||||
def minus(left, right):
|
||||
|
@ -11,8 +11,7 @@ Multiply MO
|
||||
"""
|
||||
|
||||
from ..tree import Tree
|
||||
from ..operator import OPERATORS
|
||||
from ..MO.mo import MO, MOnumber, MOstr
|
||||
from ..MO.mo import MO, MOnumber
|
||||
from ..MO.fraction import MOFraction
|
||||
from .exceptions import MultiplyError
|
||||
|
||||
|
@ -16,8 +16,8 @@ __all__ = ["coroutine", "STOOOP", "RESTAAART"]
|
||||
|
||||
def coroutine(func):
|
||||
@wraps(func)
|
||||
def start(*args,**kwargs):
|
||||
cr = func(*args,**kwargs)
|
||||
def start(*args, **kwargs):
|
||||
cr = func(*args, **kwargs)
|
||||
next(cr)
|
||||
return cr
|
||||
return start
|
||||
|
@ -126,7 +126,6 @@ def mul2tex(left, right):
|
||||
|
||||
if display_time:
|
||||
return f"{left_} \\times {right_}"
|
||||
else:
|
||||
return f"{left_}{right_}"
|
||||
|
||||
def div2tex(left, right):
|
||||
@ -199,7 +198,7 @@ def pow2tex(left, right):
|
||||
|
||||
return f"{left_} ^ {right_}"
|
||||
|
||||
OPERATOR2tex = {
|
||||
OPERATOR2TEX = {
|
||||
"+": plus2tex,
|
||||
"-": minus2tex,
|
||||
"*": mul2tex,
|
||||
@ -217,7 +216,7 @@ def tree2tex(tree):
|
||||
>>> tree2tex(t)
|
||||
'2 + 3 \\times 4'
|
||||
"""
|
||||
return OPERATOR2tex[tree.node](tree.left_value, tree.right_value)
|
||||
return OPERATOR2TEX[tree.node](tree.left_value, tree.right_value)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
|
@ -293,8 +293,6 @@ def concurent_broadcast(target, lookfors = []):
|
||||
|
||||
lookfors_ = [remember_lookfor(lkf) for lkf in lookfors]
|
||||
|
||||
stock = []
|
||||
ans = []
|
||||
try:
|
||||
while True:
|
||||
found = False
|
||||
@ -310,7 +308,7 @@ def concurent_broadcast(target, lookfors = []):
|
||||
for lf in lookfors_:
|
||||
lf.throw(RESTAAART)
|
||||
for i in found:
|
||||
ans = target_.send(i)
|
||||
target_.send(i)
|
||||
except STOOOP as err:
|
||||
for lf in lookfors_:
|
||||
last = lf.throw(RESTAAART)
|
||||
@ -380,14 +378,14 @@ def missing_times(target):
|
||||
if not previous is None:
|
||||
previous = None
|
||||
|
||||
if type(tok) == str:
|
||||
if isinstance(tok, str):
|
||||
if tok == '(':
|
||||
target_.send("*")
|
||||
elif not is_operator(tok) and tok != ')':
|
||||
target_.send("*")
|
||||
|
||||
if type(tok) == int or \
|
||||
(type(tok) == str and \
|
||||
if isinstance(tok, int) or \
|
||||
(isinstance(tok, str) and \
|
||||
not is_operator(tok) and \
|
||||
not tok == '('):
|
||||
previous = tok
|
||||
@ -462,7 +460,6 @@ def lookforNumbers(target):
|
||||
target_ = target
|
||||
|
||||
current = ""
|
||||
ans = []
|
||||
try:
|
||||
while True:
|
||||
tok = yield
|
||||
@ -473,12 +470,12 @@ def lookforNumbers(target):
|
||||
if tok == '.':
|
||||
if "." in current:
|
||||
raise ParsingError(f"Can't build a number with 2 dots (current is {current})")
|
||||
elif len(current) == 0:
|
||||
elif not current:
|
||||
raise ParsingError(f"Can't build a number starting with a dot")
|
||||
else:
|
||||
current += tok
|
||||
elif tok == '-':
|
||||
if len(current) > 0:
|
||||
if current:
|
||||
target_.send(typifiy_numbers(current))
|
||||
target_.send('+')
|
||||
current = tok
|
||||
@ -564,7 +561,7 @@ def list_sink():
|
||||
except STOOOP:
|
||||
yield ans
|
||||
|
||||
def str2(sink, convert_to_MO=True):
|
||||
def str2(sink, convert_to_mo=True):
|
||||
""" Return a pipeline which parse an expression with the sink as an endpont
|
||||
|
||||
:example:
|
||||
@ -685,9 +682,9 @@ def str2(sink, convert_to_MO=True):
|
||||
|
||||
"""
|
||||
lfop = lookfor(is_operator)
|
||||
operator_corout = partial(concurent_broadcast, lookfors = [lfop])
|
||||
operator_corout = partial(concurent_broadcast, lookfors=[lfop])
|
||||
def pipeline(expression):
|
||||
if convert_to_MO:
|
||||
if convert_to_mo:
|
||||
str2_corout = lookforNumbers(operator_corout(missing_times(moify(pparser(sink)))))
|
||||
else:
|
||||
str2_corout = lookforNumbers(operator_corout(missing_times(pparser(sink))))
|
||||
|
@ -10,11 +10,10 @@ Tree class
|
||||
"""
|
||||
|
||||
from .tree_tools import (to_nested_parenthesis,
|
||||
infix_str_concatenate,
|
||||
postfix_concatenate,
|
||||
show_tree,
|
||||
)
|
||||
from .coroutine import *
|
||||
from .coroutine import coroutine, STOOOP
|
||||
from .str2 import str2
|
||||
from .operator import OPERATORS
|
||||
|
||||
@ -55,7 +54,7 @@ class Tree(object):
|
||||
self.right_value = right_value
|
||||
|
||||
@classmethod
|
||||
def from_str(cls, expression, convert_to_MO=True):
|
||||
def from_str(cls, expression, convert_to_mo=True):
|
||||
""" Initiate a tree from an string expression
|
||||
|
||||
:example:
|
||||
@ -83,7 +82,7 @@ class Tree(object):
|
||||
| > n
|
||||
|
||||
"""
|
||||
t = MutableTree.from_str(expression, convert_to_MO)
|
||||
t = MutableTree.from_str(expression, convert_to_mo)
|
||||
return cls.from_any_tree(t)
|
||||
|
||||
@classmethod
|
||||
@ -268,7 +267,7 @@ class Tree(object):
|
||||
|
||||
:example:
|
||||
|
||||
>>> t = Tree.from_str("3*4+2", convert_to_MO=False)
|
||||
>>> t = Tree.from_str("3*4+2", convert_to_mo=False)
|
||||
>>> print(t)
|
||||
+
|
||||
> *
|
||||
@ -385,7 +384,7 @@ class Tree(object):
|
||||
|
||||
return function(self.node, left_value, right_value)
|
||||
|
||||
def get_leafs(self, callback = lambda x:x):
|
||||
def get_leafs(self, callback=lambda x:x):
|
||||
""" Generator which yield all the leaf value of the tree.
|
||||
Callback act on every leaf.
|
||||
|
||||
@ -408,7 +407,7 @@ class Tree(object):
|
||||
except AttributeError:
|
||||
yield callback(self.right_value)
|
||||
|
||||
def get_nodes(self, callback = lambda x:x):
|
||||
def get_nodes(self, callback=lambda x:x):
|
||||
""" Generator which yield all nodes of the tree.
|
||||
Callback act on every nodes.
|
||||
|
||||
@ -580,7 +579,7 @@ class MutableTree(Tree):
|
||||
self.right_value = right_value
|
||||
|
||||
@classmethod
|
||||
def from_str(cls, expression, convert_to_MO=True):
|
||||
def from_str(cls, expression, convert_to_mo=True):
|
||||
""" Initiate the MutableTree
|
||||
|
||||
:example:
|
||||
@ -606,8 +605,8 @@ class MutableTree(Tree):
|
||||
| > -2
|
||||
| > 3
|
||||
"""
|
||||
str2mutTree = str2(cls.sink, convert_to_MO)
|
||||
return str2mutTree(expression)
|
||||
str_2_mut_tree = str2(cls.sink, convert_to_mo)
|
||||
return str_2_mut_tree(expression)
|
||||
|
||||
@classmethod
|
||||
@coroutine
|
||||
@ -867,7 +866,7 @@ class AssocialTree(Tree):
|
||||
|
||||
:example:
|
||||
|
||||
>>> t = Tree.from_str("3*4+2", convert_to_MO=False)
|
||||
>>> t = Tree.from_str("3*4+2", convert_to_mo=False)
|
||||
>>> print(t)
|
||||
+
|
||||
> *
|
||||
@ -938,7 +937,7 @@ class AssocialTree(Tree):
|
||||
|
||||
return function(self.node, left_value, right_value)
|
||||
|
||||
def get_leafs(self, callback = lambda x:x):
|
||||
def get_leafs(self, callback=lambda x: x):
|
||||
""" Generator which yield all the leaf value of the tree.
|
||||
Callback act on every leaf.
|
||||
|
||||
|
@ -61,7 +61,7 @@ def postfix_concatenate(op, left, right):
|
||||
|
||||
return left_tokens + right_tokens + [op]
|
||||
|
||||
def show_tree(op, left, right, sep = "|", node_caracter = ">"):
|
||||
def show_tree(op, left, right, sep="|", node_caracter=">"):
|
||||
""" Shape argument to make nice Tree display
|
||||
|
||||
:example:
|
||||
|
Loading…
Reference in New Issue
Block a user