Skip to content

Commit 147d5c8

Browse files
committed
Add more type annotations and type hints
1 parent 84abc91 commit 147d5c8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

app.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def short_numeric_filter(
118118
Get the abbreviated numeric value.
119119
value - the numeric value to convert.
120120
"""
121-
units = [
121+
units: list[str] = [
122122
"",
123123
"K",
124124
"M",
@@ -143,7 +143,7 @@ def short_numeric_filter(
143143
"V",
144144
] # list of units with abbreviations
145145
exponent = 0
146-
mantissa = value # mantissa value from 1 to 999
146+
mantissa: Union[int, float] = value # mantissa value from 1 to 999
147147
while mantissa >= 1000: # repeat until mantissa is within 1 to 999
148148
mantissa /= 1000
149149
exponent += 1
@@ -172,8 +172,8 @@ def index() -> str: # get index page template
172172

173173
@app.route("/add", methods=["POST"])
174174
def add_task() -> Response: # add the task to the task list
175-
name = request.form.get("name") # get name from request form
176-
due_date = request.form.get("due_date") # get due date
175+
name: str = request.form.get("name") # get name from request form
176+
due_date: str = request.form.get("due_date") # get due date
177177
priority = int(request.form.get("priority")) # get priority
178178
difficulty = int(request.form.get("difficulty")) # get difficulty
179179
repeat_interval = int(
@@ -213,11 +213,11 @@ def complete_task(task_id) -> Response: # complete task from task id
213213
task.repeat_interval,
214214
task.repeat_often,
215215
) # calculate the next task due date
216-
days_to_due = (
216+
days_to_due: int = (
217217
task.due_date - date.today()
218218
).days # calculate the number of days until the task is due
219219
if days_to_due > 0: # if task due date is after today
220-
due_multiplier = 1 + 1 / (
220+
due_multiplier: float = 1 + 1 / (
221221
days_to_due + 1
222222
) # set due multiplier that increases over time when the task is closer to due date
223223
elif (
@@ -241,7 +241,7 @@ def complete_task(task_id) -> Response: # complete task from task id
241241
task.streak += 1 # increase streak by 1
242242
if task.repeat_often == 1: # if the task repetition interval is daily
243243
if task.repeat_interval < 7: # 7 days is 1 week
244-
repeat_multiplier = 1 + (task.repeat_interval - 1) / (
244+
repeat_multiplier: float = 1 + (task.repeat_interval - 1) / (
245245
7 - 1
246246
) # 1x XP multiplier for daily tasks (1 day) to 2x XP multiplier for weekly tasks (7 days)
247247
elif task.repeat_interval < 30: # approximately 30 days is 1 month
@@ -336,7 +336,7 @@ def complete_task(task_id) -> Response: # complete task from task id
336336

337337
@app.route("/delete_task/<int:task_id>")
338338
def delete_task(task_id) -> Response: # delete task from task id
339-
task = Task.query.get(task_id) # get task by task id
339+
task: Union[Task, None] = Task.query.get(task_id) # get task by task id
340340
if task:
341341
db.session.delete(task) # delete task from task list
342342
db.session.commit() # commit database changes

0 commit comments

Comments
 (0)