Feat: Move some import into functions

This commit is contained in:
Bertrand Benjamin 2019-07-15 11:09:59 +02:00
parent 071b8caf1d
commit b81281d78a
2 changed files with 8 additions and 6 deletions

View File

@ -13,7 +13,7 @@ Expression
from ..core import AssocialTree, Tree, compute, typing, TypingError from ..core import AssocialTree, Tree, compute, typing, TypingError
from ..core.random import extract_rdleaf, extract_rv, random_generator, compute_leafs, replace_rdleaf from ..core.random import extract_rdleaf, extract_rv, random_generator, compute_leafs, replace_rdleaf
from ..core.MO import moify from ..core.MO import moify
from .tokens import factory, Token from .tokens import factory
from .renders import renders from .renders import renders
@ -73,6 +73,7 @@ class Expression(object):
\\frac{11}{4} \\frac{11}{4}
>>> Expression.set_render('txt') >>> Expression.set_render('txt')
""" """
from .tokens.token import Token
Token.set_render(render) Token.set_render(render)
cls.RENDER = render cls.RENDER = render

View File

@ -16,11 +16,6 @@ from ...core.MO.monomial import MOstrPower, MOMonomial
from ...core.MO.polynomial import MOpolynomial from ...core.MO.polynomial import MOpolynomial
from decimal import Decimal as _Decimal from decimal import Decimal as _Decimal
from .number import Integer, Decimal, Fraction
from .polynomial import Polynomial, Linear, Quadratic
from .token import Token
__all__ = ["factory"] __all__ = ["factory"]
@ -63,8 +58,10 @@ def factory(exp, name="", ancestor=None):
if isinstance(mo, MOnumber): if isinstance(mo, MOnumber):
if isinstance(mo.value, int): if isinstance(mo.value, int):
from .number import Integer
return Integer.from_mo(mo, name, ancestor) return Integer.from_mo(mo, name, ancestor)
elif isinstance(mo.value, _Decimal): elif isinstance(mo.value, _Decimal):
from .number import Decimal
return Decimal.from_mo(mo, name, ancestor) return Decimal.from_mo(mo, name, ancestor)
raise TypeError(f"Can't build from MOnumber ({mo}) neither int nor decimal") raise TypeError(f"Can't build from MOnumber ({mo}) neither int nor decimal")
@ -73,6 +70,7 @@ def factory(exp, name="", ancestor=None):
if isinstance(mo._denominator, MOnumber) and isinstance( if isinstance(mo._denominator, MOnumber) and isinstance(
mo._numerator, MOnumber mo._numerator, MOnumber
): ):
from .number import Fraction
return Fraction.from_mo(mo, name, ancestor) return Fraction.from_mo(mo, name, ancestor)
raise TypeError( raise TypeError(
@ -89,14 +87,17 @@ def factory(exp, name="", ancestor=None):
or (isinstance(mo, MOMonomial) and mo.power.value == 1) or (isinstance(mo, MOMonomial) and mo.power.value == 1)
or (isinstance(mo, MOpolynomial) and mo.power.value == 1) or (isinstance(mo, MOpolynomial) and mo.power.value == 1)
): ):
from .polynomial import Linear
return Linear.from_mo(mo, name, ancestor) return Linear.from_mo(mo, name, ancestor)
elif ( elif (
(isinstance(mo, MOstrPower) and mo.power.value == 2) (isinstance(mo, MOstrPower) and mo.power.value == 2)
or (isinstance(mo, MOMonomial) and mo.power.value == 2) or (isinstance(mo, MOMonomial) and mo.power.value == 2)
or (isinstance(mo, MOpolynomial) and mo.power.value == 2) or (isinstance(mo, MOpolynomial) and mo.power.value == 2)
): ):
from .polynomial import Quadratic
return Quadratic.from_mo(mo, name, ancestor) return Quadratic.from_mo(mo, name, ancestor)
else: else:
from .polynomial import Polynomial
return Polynomial.from_mo(mo, name, ancestor) return Polynomial.from_mo(mo, name, ancestor)
else: else: