From bfc8ede763c689f4045b5d4fccac2d10b158f0c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Charlier?= <clement.charlier@student-cs.fr> Date: Thu, 13 Oct 2022 17:50:28 +0200 Subject: [PATCH] mod --- calculator/expression.py | 3 ++- calculator/operators.py | 11 +++++++---- calculator/server.py | 4 +++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/calculator/expression.py b/calculator/expression.py index 1a27f0c..a2e750b 100644 --- a/calculator/expression.py +++ b/calculator/expression.py @@ -1,8 +1,9 @@ """ Expression module defines the structure of an expression. """ -from calculator.operators import Operator from typing import Union +from calculator.operators import Operator + Term: type = int Token: type = Union[Operator, Term] diff --git a/calculator/operators.py b/calculator/operators.py index f855332..9732f2c 100644 --- a/calculator/operators.py +++ b/calculator/operators.py @@ -6,9 +6,9 @@ class Operator: Operator class is a binary operator with a symbol, a precedence and an evaluation function. """ def __init__(self, symbol, precedence, evaluate_function): - self.symbol = symbol - self.precedence = precedence - self.evaluate_function = evaluate_function + self.symbol = symbol + self.precedence = precedence + self.evaluate_function = evaluate_function def __repr__(self): return self.symbol @@ -17,4 +17,7 @@ class Operator: return self.evaluate_function(left, right) -STANDARD_OPERATORS = { '+': Operator('+', 1, lambda a, b: a + b),'-': Operator('-', 1, lambda a, b: a - b),'*': Operator('×', 2, lambda a, b: a * b),'/': Operator('/', 2, lambda a, b: a / b)} +STANDARD_OPERATORS = { '+': Operator('+', 1, lambda a, b: a + b), +'-': Operator('-', 1, lambda a, b: a - b), +'*': Operator('×', 2, lambda a, b: a * b), +'/': Operator('/', 2, lambda a, b: a / b)} diff --git a/calculator/server.py b/calculator/server.py index e0dc49a..0e0af20 100644 --- a/calculator/server.py +++ b/calculator/server.py @@ -1,7 +1,9 @@ -from calculator.calculator import Calculator +"""Import des modules""" from fastapi import FastAPI from fastapi.requests import Request from fastapi.templating import Jinja2Templates +from calculator.calculator import Calculator + app = FastAPI() templates = Jinja2Templates(directory="calculator/templates") -- GitLab