Skip to content
Snippets Groups Projects
Commit 90a68ff1 authored by Florentin Labelle's avatar Florentin Labelle
Browse files

Correction

parent 872586f6
Branches tp1-correction
No related tags found
No related merge requests found
image: python:3.10 image: python:3.10
stages: stages:
- dependencies
- lint - lint
download_dependencies:
stage: dependencies
before_script:
- python -m venv .venv
- source .venv/bin/activate
script:
- pip install -r requirements.txt
artifacts:
paths:
- .venv
pylint: pylint:
stage: lint stage: lint
dependencies:
- download_dependencies
before_script:
- source .venv/bin/activate
script: script:
- python -m venv .venv
- source .venv/bin/activate
- pip install -r requirements.txt
# C'est à ton tour de coder un script qui lance pylint sur ton projet # C'est à ton tour de coder un script qui lance pylint sur ton projet
- - pip install pylint
- pylint calculator --fail-on=warning
""" """
Expression module defines the structure of an expression. Expression module defines the structure of an expression.
""" """
from calculator.operators import Operator
from typing import Union from typing import Union
from calculator.operators import Operator
Term: type = int Term: type = int
Token: type = Union[Operator, Term] Token: type = Union[Operator, Term]
...@@ -12,6 +13,7 @@ class OperatorExpression: ...@@ -12,6 +13,7 @@ class OperatorExpression:
""" """
OperatorExpression class is an expression that contains an operator and two sub-expressions. OperatorExpression class is an expression that contains an operator and two sub-expressions.
""" """
def __init__(self, operator: Operator, left, right): def __init__(self, operator: Operator, left, right):
self.operator = operator self.operator = operator
self.left = left self.left = left
...@@ -28,6 +30,7 @@ class TermExpression: ...@@ -28,6 +30,7 @@ class TermExpression:
""" """
TermExpression class is an expression that contains a single term. TermExpression class is an expression that contains a single term.
""" """
def __init__(self, value: Term): def __init__(self, value: Term):
self.value = value self.value = value
......
""" """
Operator module contains the Operator class and a list of standard operators. Operator module contains the Operator class and a list of standard operators.
""" """
class Operator: class Operator:
""" """
Operator class is a binary operator with a symbol, a precedence and an evaluation function. Operator class is a binary operator with a symbol, a precedence and an evaluation function.
""" """
def __init__(self, symbol, precedence, evaluate_function): def __init__(self, symbol, precedence, evaluate_function):
self.symbol = symbol self.symbol = symbol
self.precedence = precedence self.precedence = precedence
...@@ -17,4 +20,9 @@ class Operator: ...@@ -17,4 +20,9 @@ class Operator:
return self.evaluate_function(left, right) 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)
}
from calculator.calculator import Calculator """
C'est le module qui s'occupe du web server
"""
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.requests import Request from fastapi.requests import Request
from fastapi.templating import Jinja2Templates from fastapi.templating import Jinja2Templates
from calculator.calculator import Calculator
app = FastAPI() app = FastAPI()
templates = Jinja2Templates(directory="calculator/templates") templates = Jinja2Templates(directory="calculator/templates")
calc = Calculator() calc = Calculator()
@app.get("/") @app.get("/")
async def root(request: Request): async def root(request: Request):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment