Style: apply black
This commit is contained in:
@@ -15,6 +15,7 @@ from ..coroutine import coroutine, STOOOP
|
||||
|
||||
__all__ = ["moify", "MOnumber", "MOstr"]
|
||||
|
||||
|
||||
@coroutine
|
||||
def moify(target):
|
||||
""" Coroutine which try to convert a parsed token into an MO
|
||||
@@ -47,6 +48,7 @@ def moify(target):
|
||||
except STOOOP as err:
|
||||
yield target_.throw(err)
|
||||
|
||||
|
||||
@total_ordering
|
||||
class MOnumber(Atom):
|
||||
|
||||
@@ -116,8 +118,10 @@ class MOnumber(Atom):
|
||||
elif isinstance(value, float):
|
||||
Atom.__init__(self, Decimal(value))
|
||||
else:
|
||||
raise MOError("The value of an MOnumber need to be a int, a float or a Decimal",
|
||||
f"(got {type(value)})")
|
||||
raise MOError(
|
||||
"The value of an MOnumber need to be a int, a float or a Decimal",
|
||||
f"(got {type(value)})",
|
||||
)
|
||||
|
||||
self._signature = "scalar"
|
||||
|
||||
@@ -215,9 +219,13 @@ class MOstr(Atom):
|
||||
val = value
|
||||
|
||||
if not isinstance(val, str):
|
||||
raise MOError(f"An MOstr should be initiate with a string - the unknown, got {val}")
|
||||
raise MOError(
|
||||
f"An MOstr should be initiate with a string - the unknown, got {val}"
|
||||
)
|
||||
if len(val) != 1:
|
||||
raise MOError(f"An MOstr should be initiate with a single caracter string, got {val}")
|
||||
raise MOError(
|
||||
f"An MOstr should be initiate with a single caracter string, got {val}"
|
||||
)
|
||||
if not val.isalpha():
|
||||
raise MOError(f"An MOstr should be initiate with a alpha string, got {val}")
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
Exceptions for core tools
|
||||
"""
|
||||
|
||||
|
||||
class MOError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ from .mo import Molecule, MO
|
||||
|
||||
__all__ = ["MOFraction"]
|
||||
|
||||
|
||||
class MOFraction(Molecule):
|
||||
|
||||
""" Fraction math object"""
|
||||
@@ -42,10 +43,7 @@ class MOFraction(Molecule):
|
||||
"""
|
||||
_numerator = MO.factory(numerator)
|
||||
_denominator = MO.factory(denominator)
|
||||
base_tree = Tree("/",
|
||||
_numerator,
|
||||
_denominator,
|
||||
)
|
||||
base_tree = Tree("/", _numerator, _denominator)
|
||||
if negative:
|
||||
tree = Tree("-", None, base_tree)
|
||||
else:
|
||||
@@ -71,9 +69,8 @@ class MOFraction(Molecule):
|
||||
|
||||
def inverse(self):
|
||||
""" return the inverse fraction """
|
||||
return MOFraction(self._denominator,
|
||||
self._numerator,
|
||||
self.negative)
|
||||
return MOFraction(self._denominator, self._numerator, self.negative)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
|
||||
@@ -12,6 +12,7 @@ from ..renders import tree2txt, tree2tex
|
||||
|
||||
__all__ = ["MO"]
|
||||
|
||||
|
||||
class MO(ABC):
|
||||
|
||||
"""MO for math object
|
||||
@@ -50,7 +51,6 @@ class MO(ABC):
|
||||
|
||||
return Atom.factory(value)
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def content(self):
|
||||
""" content of the mo """
|
||||
@@ -97,6 +97,7 @@ class MO(ABC):
|
||||
"""
|
||||
return self._signature
|
||||
|
||||
|
||||
class Atom(MO):
|
||||
|
||||
""" Base Math Object with only one component.
|
||||
@@ -196,8 +197,6 @@ class Molecule(MO):
|
||||
return tree2tex(self._tree)
|
||||
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
|
||||
@@ -13,6 +13,7 @@ from .exceptions import MOError
|
||||
|
||||
__all__ = ["MOMonomial"]
|
||||
|
||||
|
||||
class MOstrPower(Molecule):
|
||||
|
||||
""" Power of a MOstr """
|
||||
@@ -68,10 +69,7 @@ class MOstrPower(Molecule):
|
||||
raise MOError("The power of a monomial should be a integer")
|
||||
self._power = _power
|
||||
|
||||
_tree = Tree("^",
|
||||
self._variable,
|
||||
self._power,
|
||||
)
|
||||
_tree = Tree("^", self._variable, self._power)
|
||||
|
||||
Molecule.__init__(self, _tree)
|
||||
|
||||
@@ -113,6 +111,7 @@ class MOstrPower(Molecule):
|
||||
"""
|
||||
return f"monome{self.power}"
|
||||
|
||||
|
||||
class MOMonomial(Molecule):
|
||||
|
||||
""" Monomial math object"""
|
||||
@@ -164,7 +163,9 @@ class MOMonomial(Molecule):
|
||||
if coefficient == 0:
|
||||
raise MOError("The coefficient of a monomial should not be 0")
|
||||
elif coefficient == 1:
|
||||
raise MOError("The coefficient of a monomial should not be 1, it is a MOstrPower or MOstr")
|
||||
raise MOError(
|
||||
"The coefficient of a monomial should not be 1, it is a MOstrPower or MOstr"
|
||||
)
|
||||
self._coefficient = _coefficient
|
||||
|
||||
_variable = MO.factory(variable)
|
||||
@@ -174,7 +175,9 @@ class MOMonomial(Molecule):
|
||||
elif isinstance(_variable, MOstr):
|
||||
_power = MO.factory(power)
|
||||
else:
|
||||
raise MOError(f"variable need to be a MOstrPower or a MOstr. Got {type(variable)}.")
|
||||
raise MOError(
|
||||
f"variable need to be a MOstrPower or a MOstr. Got {type(variable)}."
|
||||
)
|
||||
|
||||
self._variable = _variable
|
||||
self._power = _power
|
||||
@@ -187,10 +190,8 @@ class MOMonomial(Molecule):
|
||||
except AttributeError:
|
||||
_tree = Tree("*", self._coefficient, self.strpower)
|
||||
|
||||
|
||||
Molecule.__init__(self, _tree)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
if self._coefficient != -1:
|
||||
return super(MOMonomial, self).__str__()
|
||||
@@ -244,6 +245,7 @@ class MOMonomial(Molecule):
|
||||
@property
|
||||
def degree(self):
|
||||
return self._power.value
|
||||
|
||||
@property
|
||||
def signature(self):
|
||||
""" Name of the mo in the API
|
||||
@@ -256,6 +258,7 @@ class MOMonomial(Molecule):
|
||||
"""
|
||||
return f"monome{self.power}"
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
|
||||
@@ -14,6 +14,7 @@ from .monomial import MOMonomial, MOstrPower
|
||||
|
||||
__all__ = ["MOpolynomial"]
|
||||
|
||||
|
||||
class MOpolynomial(Molecule):
|
||||
|
||||
""" MO polynomial"""
|
||||
@@ -45,11 +46,13 @@ class MOpolynomial(Molecule):
|
||||
self._variable = _variable
|
||||
|
||||
if isinstance(coefs, dict):
|
||||
_coefs = {MO.factory(d): MO.factory(c) for (d, c) in coefs.items()
|
||||
if c != 0 }
|
||||
_coefs = {
|
||||
MO.factory(d): MO.factory(c) for (d, c) in coefs.items() if c != 0
|
||||
}
|
||||
elif isinstance(coefs, list):
|
||||
_coefs = {MO.factory(d): MO.factory(c) for (d, c) in enumerate(coefs)
|
||||
if c != 0 }
|
||||
_coefs = {
|
||||
MO.factory(d): MO.factory(c) for (d, c) in enumerate(coefs) if c != 0
|
||||
}
|
||||
else:
|
||||
raise TypeError("Coefs needs to be a dictionnary or a list")
|
||||
self._coefs = _coefs
|
||||
|
||||
Reference in New Issue
Block a user