Skip to content

Commit

Permalink
Enable MyPy
Browse files Browse the repository at this point in the history
Need to add ignores for the Flask-SQLAlchemy model declarations
as a workaround for limitations regarding inheritance from objects, see
python/mypy#8603
  • Loading branch information
stsnel committed Mar 17, 2023
1 parent d70ddbd commit 7417174
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Check static typing
run: |
mypy . --explicit-package-bases || true
mypy yoda_eus --explicit-package-bases
- name: Check code for common misspellings
run: |
Expand Down
24 changes: 12 additions & 12 deletions yoda_eus/app.py
Expand Up @@ -7,7 +7,7 @@
import urllib.parse
from datetime import datetime
from os import path
from typing import Dict
from typing import Any, Dict

import bcrypt
from flask import abort, Flask, jsonify, make_response, render_template, request, Response, send_from_directory
Expand All @@ -22,7 +22,7 @@
db = SQLAlchemy()


class User(db.Model):
class User(db.Model): # type: ignore
__tablename__ = "users"
id = db.Column(db.Integer, db.Sequence("users_id_seq"), primary_key=True)
username = db.Column(db.String(64), nullable=False, unique=True, index=True)
Expand All @@ -35,7 +35,7 @@ class User(db.Model):
user_zones = db.relationship("UserZone", back_populates="user")


class UserZone(db.Model):
class UserZone(db.Model): # type: ignore
__tablename__ = "user_zones"
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), primary_key=True)
inviter_user = db.Column(db.String(255), nullable=False)
Expand All @@ -44,7 +44,7 @@ class UserZone(db.Model):
user = db.relationship("User", back_populates="user_zones")


def create_app(config_filename="flask.cfg", enable_api=True) -> Flask:
def create_app(config_filename: str = "flask.cfg", enable_api: bool = True) -> Flask:
# create a minimal app
app = Flask(__name__,
static_folder="/var/www/yoda/static/",
Expand Down Expand Up @@ -322,10 +322,10 @@ def process_activate_account_form(hash: str) -> Response:
# Sanity checks secret hash
if hash is None or hash == "":
# Failsafe
params = {"activation_error_message": "Activation link is invalid"}
return render_template('activation-error.html', **params), 403
else:
params = {"secret_hash": hash}
failed_params = {"activation_error_message": "Activation link is invalid"}
return render_template('activation-error.html', **failed_params), 403

params: Dict[str, Any] = {"secret_hash": hash}

# Validate secret hash and handle errors
users = User.query.filter_by(hash=hash).all()
Expand Down Expand Up @@ -402,10 +402,10 @@ def process_reset_password_form(hash: str) -> Response:
# Sanity checks secret hash
if hash is None or hash == "":
# Failsafe
params = {"reset_error_message": "Password reset link is invalid"}
return render_template('reset-password-error.html', **params), 403
else:
params = {"secret_hash": hash}
failed_params = {"reset_error_message": "Password reset link is invalid"}
return render_template('reset-password-error.html', **failed_params), 403

params: Dict[str, Any] = {"secret_hash": hash}

# Validate secret hash and handle errors
users = User.query.filter_by(hash=hash).all()
Expand Down
3 changes: 2 additions & 1 deletion yoda_eus/password_complexity.py
Expand Up @@ -2,9 +2,10 @@
__license__ = 'GPLv3, see LICENSE'

import string
from typing import List


def check_password_complexity(password: str) -> list:
def check_password_complexity(password: str) -> List[str]:
"""Checks whether a password meets EUS password complexity requirements.
:param password: Password to check
Expand Down

0 comments on commit 7417174

Please sign in to comment.