Skip to content

Commit 362d8a8

Browse files
committed
Update type hints for new flask version.
1 parent d899251 commit 362d8a8

File tree

6 files changed

+62
-28
lines changed

6 files changed

+62
-28
lines changed

dependency_dash/_app.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# 3rd party
3838
from domdf_python_tools.paths import PathPlus
39-
from flask import Flask, Response, redirect, request, url_for # type: ignore[import]
39+
from flask import Flask, Response, redirect, request, url_for
4040
from flask_restx import Api # type: ignore[import]
4141
from wtforms import Form, StringField # type: ignore[import]
4242

@@ -82,17 +82,22 @@ def https_redirect() -> Optional[Response]:
8282
if request.scheme != "http":
8383
return None
8484

85-
return redirect(
85+
view_args: Dict[str, Any] = request.view_args or {}
86+
args: Dict[str, Any] = dict(request.args or {})
87+
88+
retval = redirect(
8689
url_for(
8790
request.endpoint,
8891
_scheme="https",
8992
_external=True,
90-
**(request.view_args or {}),
91-
**(request.args or {}),
93+
**view_args,
94+
**args,
9295
),
9396
HTTPStatus.PERMANENT_REDIRECT,
9497
)
9598

99+
return retval # type: ignore[return-value]
100+
96101

97102
if "ON_HEROKU" in os.environ:
98103
app.before_request(https_redirect)

dependency_dash/github/__init__.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
import github3.repos.contents
4545
import platformdirs
4646
import requests
47-
import setup_py_upgrade # type: ignore
47+
import setup_py_upgrade # type: ignore[import]
4848
from domdf_python_tools.paths import PathPlus
49-
from flask import Response, render_template, request # type: ignore
49+
from flask import Response, render_template, request
5050
from github3.orgs import Organization
5151
from github3.repos import ShortRepository
5252
from github3.users import User
@@ -57,7 +57,7 @@
5757
# this package
5858
from dependency_dash._app import app
5959
from dependency_dash.github._env import GITHUB
60-
from dependency_dash.github.api import GitHubProjectAPI
60+
from dependency_dash.github.api import GitHubProjectAPI # noqa: F401
6161
from dependency_dash.htmx import htmx
6262
from dependency_dash.pypi import format_project_links, get_dependency_status, make_badge
6363

@@ -348,7 +348,7 @@ def get_repo_requirements(
348348

349349

350350
@app.route("/github/<username>/<repository>/")
351-
def github_project(username: str, repository: str):
351+
def github_project(username: str, repository: str) -> Response:
352352
"""
353353
Route for displaying information about a single github repository.
354354
@@ -361,17 +361,22 @@ def github_project(username: str, repository: str):
361361
try:
362362
repo = GITHUB.repository(username, repository)
363363
except github3.exceptions.NotFoundError:
364-
return render_template(
365-
"project_404.html",
366-
project_name=project_name,
367-
description=f"Dependency status for https://github.com/{project_name}",
368-
), 404
364+
return Response(
365+
render_template(
366+
"project_404.html",
367+
project_name=project_name,
368+
description=f"Dependency status for https://github.com/{project_name}",
369+
),
370+
404
371+
)
369372

370-
return render_template(
371-
"project.html",
372-
project_name=repo.full_name,
373-
data_url=f"/htmx/github/{repo.full_name}/{repo.default_branch}",
374-
description=f"Dependency status for https://github.com/{repo.full_name}",
373+
return Response(
374+
render_template(
375+
"project.html",
376+
project_name=repo.full_name,
377+
data_url=f"/htmx/github/{repo.full_name}/{repo.default_branch}",
378+
description=f"Dependency status for https://github.com/{repo.full_name}",
379+
)
375380
)
376381

377382

@@ -504,7 +509,7 @@ def htmx_github_user(username: str) -> str:
504509
except (InvalidRequirement, InvalidVersion):
505510
return render_template("repository_status.html", status="invalid")
506511

507-
page = request.args.get("page", 1)
512+
page = int(request.args.get("page", 1))
508513

509514
try:
510515
user = GITHUB.user(username)
@@ -679,3 +684,19 @@ def get_our_config(
679684
}
680685
datafile.dump_json(data)
681686
return files
687+
688+
689+
#
690+
# def parse_config():
691+
# """
692+
#
693+
# Possible syntax:
694+
#
695+
# * Filename to ``requirements.txt``-style.
696+
# * ``setup.cfg`` -- to consider the library requirements
697+
# # * ``setup.cfg[extra1, extra2]`` -- to consider the extras with the given name
698+
# * ``pyproject.toml`` -- to consider the library requirements
699+
# # * ``pyproject.toml[extra1, extra2]`` -- to consider the extras with the given name
700+
#
701+
# :return:
702+
# """

dependency_dash/github/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class GitHubProjectAPI(Resource):
7979
@api.response(200, "Success", github_project_model)
8080
@api.response(404, "Repository not found or no supported files in repository.")
8181
@api.doc(id="get_github_project")
82-
def get(self, username: str, repository: str):
82+
def get(self, username: str, repository: str) -> Tuple[Dict, int]:
8383
"""
8484
Returns a JSON response, giving the status for each of the repository's dependencies.
8585
"""
@@ -111,11 +111,11 @@ def get(self, username: str, repository: str):
111111
req_data["current_version"] = req_data.pop("version")
112112
output[filename].append({"requirement": str(req), "status": status, **req_data})
113113

114-
return output
114+
return output, 200
115115

116116

117117
@app.route("/api/<path:path>")
118-
def api_error_404(path: str):
118+
def api_error_404(path: str) -> Tuple[Dict[str, str], int]:
119119
return {
120120
"message": "Not Found",
121121
"documentation_url": urljoin(app.config["DD_ROOT_URL"], "/api"),

dependency_dash/htmx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from urllib.parse import urljoin
3636

3737
# 3rd party
38-
from flask import Flask, render_template # type: ignore[import]
38+
from flask import Flask, render_template
3939

4040
__all__ = ["htmx"]
4141

dependency_dash/pypi/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# 3rd party
3636
import platformdirs
3737
from domdf_python_tools.paths import PathPlus
38-
from flask import render_template # type: ignore[import]
38+
from flask import render_template
3939
from packaging.version import InvalidVersion, Version
4040
from pybadges import badge
4141
from pypi_json import PyPIJSON
@@ -128,14 +128,19 @@ def get_data(project_name: str) -> Dict[str, Any]:
128128
with PyPIJSON() as client:
129129
metadata = client.get_metadata(project_name)
130130

131+
releases = metadata.releases
132+
# .releases may be None if a version is passed,
133+
# but in our case we aren't.
134+
assert releases is not None
135+
131136
data = {
132137
"name": metadata.info["name"],
133138
"version": metadata.info["version"],
134139
"home_page": metadata.info["home_page"] or '',
135140
"license": metadata.info["license"] or '',
136141
"package_url": metadata.info["package_url"],
137142
"project_urls": metadata.info["project_urls"],
138-
"all_versions": _sort_versions(*metadata.releases.keys()),
143+
"all_versions": _sort_versions(*releases.keys()),
139144
}
140145

141146
datafile.dump_json(data)

dependency_dash/routes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
from typing import Tuple
3131

3232
# 3rd party
33-
import jinja2 # type: ignore[import]
33+
import jinja2
3434
import markdown
3535
from domdf_python_tools.compat import importlib_resources
36-
from flask import Response, make_response, redirect, render_template, request # type: ignore[import]
36+
from flask import Response, make_response, redirect, render_template, request
3737
from markdown.inlinepatterns import IMAGE_LINK_RE, ImageInlineProcessor
3838

3939
# this package
@@ -143,7 +143,10 @@ def search() -> Response:
143143
Only accepts POST requests.
144144
"""
145145

146-
return redirect(f"/github/{GoToForm(request.form).data['search']}", code=302)
146+
return redirect( # type: ignore[return-value]
147+
f"/github/{GoToForm(request.form).data['search']}",
148+
code=302,
149+
)
147150

148151

149152
@app.errorhandler(404)

0 commit comments

Comments
 (0)