flake8 corr (not finish yet)
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
# encoding: utf-8
|
||||
|
||||
# debuging
|
||||
#from debug.tools import report
|
||||
# from debug.tools import report
|
||||
|
||||
from .generic import Stack, flatten_list, expand_list, isNumber, isOperator, isNumerand
|
||||
from .generic import flatten_list, expand_list, isOperator, isNumerand
|
||||
from .str2tokens import str2tokens
|
||||
from .operator import op
|
||||
from .explicable import Explicable, Explicable_int, Explicable_Decimal
|
||||
@@ -14,6 +14,7 @@ from .random_expression import RdExpression
|
||||
|
||||
__all__ = ['Expression']
|
||||
|
||||
|
||||
def pstf_factory(pstf_tokens):
|
||||
"""Factory which tranform postfix tokens list into an Expression or the simpliest object type ready to be rendered
|
||||
|
||||
@@ -38,9 +39,7 @@ def pstf_factory(pstf_tokens):
|
||||
< Fraction 1 / 2>
|
||||
|
||||
"""
|
||||
try:
|
||||
l_pstf_token = len(pstf_tokens)
|
||||
except TypeError:
|
||||
if len(pstf_tokens) == 1:
|
||||
if isinstance(pstf_tokens[0], int):
|
||||
return Explicable_int(pstf_tokens[0])
|
||||
elif isinstance(pstf_tokens[0], Decimal):
|
||||
@@ -49,22 +48,9 @@ def pstf_factory(pstf_tokens):
|
||||
return Explicable_Decimal(Decimal(str(pstf_tokens[0])))
|
||||
elif hasattr(pstf_tokens[0], 'STR_RENDER'):
|
||||
return pstf_tokens[0]
|
||||
else:
|
||||
return Expression(self)
|
||||
else:
|
||||
if l_pstf_token == 1:
|
||||
if isinstance(pstf_tokens[0], int):
|
||||
return Explicable_int(pstf_tokens[0])
|
||||
elif isinstance(pstf_tokens[0], Decimal):
|
||||
return Explicable_Decimal(pstf_tokens[0])
|
||||
elif isinstance(pstf_tokens[0], float):
|
||||
return Explicable_Decimal(Decimal(str(pstf_tokens[0])))
|
||||
elif hasattr(pstf_tokens[0], 'STR_RENDER'):
|
||||
return pstf_tokens[0]
|
||||
else:
|
||||
return Expression(self)
|
||||
else:
|
||||
return Expression(pstf_tokens)
|
||||
|
||||
return Expression(pstf_tokens)
|
||||
|
||||
|
||||
class Expression(Explicable):
|
||||
"""A calculus expression. Today it can andle only expression with numbers later it will be able to manipulate unknown"""
|
||||
@@ -84,7 +70,6 @@ class Expression(Explicable):
|
||||
|
||||
@classmethod
|
||||
def tmp_render(cls, render=lambda _, x: pstf_factory(x)):
|
||||
# def tmp_render(cls, render=lambda _, x: Expression(x)):
|
||||
""" Same ad tmp_render for Renderable but default render is Expression
|
||||
|
||||
>>> exp = Expression("2*3/5")
|
||||
@@ -179,9 +164,9 @@ class Expression(Explicable):
|
||||
try:
|
||||
self.simplified = self.postfix_tokens[0].simplify()
|
||||
except AttributeError:
|
||||
if isinstance(self.postfix_tokens[0],int):
|
||||
if isinstance(self.postfix_tokens[0], int):
|
||||
self.simplified = Explicable_int(self.postfix_tokens[0])
|
||||
elif isinstance(self.postfix_tokens[0],Decimal):
|
||||
elif isinstance(self.postfix_tokens[0], Decimal):
|
||||
self.simplified = Explicable_Decimal(self.postfix_tokens[0])
|
||||
else:
|
||||
self.simplified = self
|
||||
@@ -411,36 +396,10 @@ class Expression(Explicable):
|
||||
class ExpressionError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ComputeError(Exception):
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('\n')
|
||||
A = Expression("( -8 x + 8 ) ( -8 - ( -6 x ) )")
|
||||
Ar = A.simplify()
|
||||
for i in Ar.explain():
|
||||
print(i)
|
||||
# print("------------")
|
||||
# for i in Ar.explain():
|
||||
# print(i)
|
||||
|
||||
# print(type(Ar))
|
||||
|
||||
# print('\n-----------')
|
||||
#A = Expression("-6 / 3 + 10 / -5")
|
||||
#Ar = A.simplify()
|
||||
# for i in Ar.explain():
|
||||
# print(i)
|
||||
|
||||
# print('\n-----------')
|
||||
#A = Expression("1/3 + 4/6")
|
||||
#Ar = A.simplify()
|
||||
# for i in Ar.explain():
|
||||
# print(i)
|
||||
|
||||
#import doctest
|
||||
# doctest.testmod()
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
|
||||
Reference in New Issue
Block a user