Skip to content

Commit

Permalink
Tight up type checking; eliminate remaining type errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
liffiton committed Jun 19, 2024
1 parent 46115d6 commit e2b134a
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ ignore = [
[tool.mypy]
files = [ "src/**/*.py" ]
strict = "True"
warn_return_any = "False"
pretty = "True"
3 changes: 2 additions & 1 deletion src/codehelp/class_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@


def _default_langs() -> list[str]:
return current_app.config['DEFAULT_LANGUAGES']
langs: list[str] = current_app.config['DEFAULT_LANGUAGES'] # declaration keeps mypy happy
return langs


@dataclass(frozen=True)
Expand Down
2 changes: 1 addition & 1 deletion src/gened/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def get_auth() -> AuthDict:
if 'auth' not in g:
g.auth = _get_auth_from_session()

return g.auth
return g.auth # type: ignore[no-any-return]


def get_last_role(user_id: int) -> int | None:
Expand Down
2 changes: 1 addition & 1 deletion src/gened/class_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def get_class_config(config_class: type[T]) -> T:
class_config_dict = json.loads(config_row['config'])
g.class_config = config_class(**class_config_dict)

return g.class_config
return g.class_config # type: ignore [no-any-return]


@bp.route("/")
Expand Down
1 change: 1 addition & 0 deletions src/gened/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class name from the LMS
db.execute("UPDATE classes SET name=? WHERE id=?", [class_name, class_row['id']])
db.commit()

assert isinstance(class_row['id'], int)
return class_row['id']

else:
Expand Down
2 changes: 1 addition & 1 deletion src/gened/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import dataclass
from pathlib import Path

import frontmatter
import frontmatter # type: ignore [import-untyped]
from flask import Blueprint, abort, current_app, render_template
from markdown_it import MarkdownIt

Expand Down
9 changes: 5 additions & 4 deletions src/gened/lti.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
session,
url_for,
)
from pylti.flask import lti
from pylti.flask import LTI # type: ignore [import-untyped]
from pylti.flask import lti as lti_flask
from werkzeug.wrappers.response import Response

from .auth import (
Expand All @@ -39,8 +40,8 @@ def lti_error(exception: dict[str, Any]) -> tuple[str, int]:
# https://github.com/mitodl/pylti/blob/master/pylti/flask.py
# https://github.com/mitodl/mit_lti_flask_sample
@bp.route("/", methods=['GET', 'POST'])
@lti(request='initial', error=lti_error)
def lti_login(lti=lti) -> Response | tuple[str, int]:
@lti_flask(request='initial', error=lti_error) # type: ignore [misc]
def lti_login(lti: LTI) -> Response | tuple[str, int]: # noqa: ARG001 (unused argument required by lti_flask decorator)
authenticated = session.get("lti_authenticated", False)
role = session.get("roles", "").lower()
full_name = session.get("lis_person_name_full", None)
Expand Down Expand Up @@ -130,5 +131,5 @@ def lti_config() -> tuple[str, int, dict[str, str]]:

#@bp.route("debug", methods=['GET'])
#@lti(request='session')
#def lti_debug(lti=lti):
#def lti_debug(lti: LTI):
# return {var: session[var] for var in session}
6 changes: 4 additions & 2 deletions src/gened/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: AGPL-3.0-only

from authlib.integrations.flask_client import OAuth, OAuthError
from authlib.integrations.flask_client import OAuth, OAuthError # type: ignore [import-untyped]
from flask import Blueprint, abort, current_app, redirect, request, session, url_for
from flask.app import Flask
from werkzeug.wrappers.response import Response
Expand Down Expand Up @@ -65,7 +65,9 @@ def login(provider_name: str) -> Response:
session[NEXT_URL_SESSION_KEY] = next_url

redirect_uri = url_for('.auth', provider_name=provider_name, _external=True)
return client.authorize_redirect(redirect_uri)
redir = client.authorize_redirect(redirect_uri)
assert isinstance(redir, Response)
return redir


@bp.route('/auth/<string:provider_name>')
Expand Down

0 comments on commit e2b134a

Please sign in to comment.