From 5e045cc1196a9ef533e3bfbf31ec9981377394a3 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Wed, 25 May 2022 17:48:10 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- src/pyflask/api.py | 7 ++----- src/pyflask/calc.py | 8 ++++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/pyflask/api.py b/src/pyflask/api.py index 5287b80..b9685ae 100644 --- a/src/pyflask/api.py +++ b/src/pyflask/api.py @@ -28,8 +28,7 @@ class HelloWorld(Resource): @api.response(200, "Success") @api.response(400, "Validation Error") def get(self): - response = "Server active!!" - return response + return "Server active!!" # Request parser documentation can be found here: https://flask-restx.readthedocs.io/en/latest/parsing.html @@ -58,10 +57,8 @@ def post(self): args = parser.parse_args() formula = args["expression"] - response = str(calc(formula)) - # restx will automatically jsonify dictionaries. You don't need to import the jsonify method from flask - return response + return str(calc(formula)) # 5000 is the flask default port. You can change it to something else if you want. diff --git a/src/pyflask/calc.py b/src/pyflask/calc.py index 12e40b0..56f75bc 100644 --- a/src/pyflask/calc.py +++ b/src/pyflask/calc.py @@ -57,7 +57,7 @@ def calc(s): if isUnary: opStk.append('#') else: - while (len(opStk) > 0): + while opStk: if ((getAssoc(s[i]) == "LEFT" and getPrec(s[i]) <= getPrec(opStk[-1])) or (getAssoc(s[i]) == "RIGHT" and getPrec(s[i]) < getPrec(opStk[-1]))): op = opStk.pop() @@ -75,7 +75,7 @@ def calc(s): opStk.append(s[i]) isUnary = True else: - while (len(opStk) > 0): + while opStk: op = opStk.pop() if (op == '('): break @@ -87,7 +87,7 @@ def calc(s): numStk.append(getBin(op, a, b)) i += 1 - while (len(opStk) > 0): + while opStk: op = opStk.pop() if op == '#': numStk.append(-numStk.pop()) @@ -114,5 +114,5 @@ def calc(s): ] for s in ss: res = calc(s) - print('{} = {}'.format(res, s)) + print(f'{res} = {s}') \ No newline at end of file