diff --git a/go_ji/__init__.py b/go_ji/__init__.py
index 6567bfb..2c56cc9 100644
--- a/go_ji/__init__.py
+++ b/go_ji/__init__.py
@@ -3,8 +3,18 @@ from typing import Any
import sentry_sdk
import sqlalchemy
-from flask import Config, Flask, abort, g, redirect, render_template, request, url_for
+from flask import (
+ Config,
+ Flask,
+ abort,
+ g,
+ redirect,
+ render_template,
+ request,
+ url_for,
+)
from sqlalchemy import select
+from werkzeug.wrappers.response import Response
from go_ji.db import Long, Short, User
from go_ji.db import create_session as create_db_session
@@ -64,15 +74,15 @@ def create_app(config_override: dict[str, Any] = {}) -> Flask:
)
@app.teardown_appcontext
- def shutdown_session(exception=None):
+ def shutdown_session(exception=None) -> None: # noqa: ANN001
db_session.remove()
@app.route("/")
- def index():
+ def index() -> str:
return render_template("hello.html", name=g.user.login)
@app.route("/links", methods=["POST"])
- def create_link():
+ def create_link() -> Response:
slug = request.form["slug"]
url = request.form["url"]
@@ -93,7 +103,7 @@ def create_app(config_override: dict[str, Any] = {}) -> Flask:
return redirect(url_for("index"))
@app.route("/<slug>")
- def go(slug: str):
+ def go(slug: str) -> Response:
long = db_session.scalars(
select(Long)
.join(Long.short)
@@ -112,7 +122,7 @@ def create_app(config_override: dict[str, Any] = {}) -> Flask:
# purely for testing Sentry
@app.route("/die")
- def die():
+ def die() -> str:
1 / 0 # raises an error
return "<p>Hello, World!</p>" # pragma: no cover
diff --git a/go_ji/db.py b/go_ji/db.py
index d9a1ae4..ac357ad 100644
--- a/go_ji/db.py
+++ b/go_ji/db.py
@@ -1,6 +1,6 @@
from datetime import datetime
-from sqlalchemy import ForeignKey, Text, create_engine
+from sqlalchemy import ForeignKey, Session, Text, create_engine
from sqlalchemy.orm import (
Mapped,
declarative_base,
@@ -15,7 +15,7 @@ from sqlalchemy.sql import func
Base = declarative_base()
-def create_session(url: str, debug: bool = False):
+def create_session(url: str, debug: bool = False) -> Session:
engine = create_engine(url, echo=debug)
db_session = scoped_session(
sessionmaker(autocommit=False, autoflush=False, bind=engine)
diff --git a/pyproject.toml b/pyproject.toml
index d5db907..99573da 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -38,21 +38,25 @@ strip-extras = true # silence warning that strip-extras will be the default in
[tool.ruff]
target-version = "py312"
-[tool.ruff.lint]
-select = [
- "F",
- "E4",
- "E7",
- "E9",
- "W",
- "I",
- "N",
- "TCH", # flake8-type-checking
- "UP", # pyupgrade
-]
-ignore = [
- "E741", # allow ambiguous variable names
-]
-
-[tool.ruff.format]
-docstring-code-format = true
+ [tool.ruff.lint]
+ select = [
+ "F", # pyflakes
+ "E4", # pycodestyle
+ "E7",
+ "E9",
+ "W",
+ "I", # isort
+ "N", # pep8-naming
+ "UP", # pyupgrade
+ "ANN", # flake8-annotations
+ "TCH", # flake8-type-checking
+ ]
+ ignore = [
+ "E741", # allow ambiguous variable names
+ ]
+
+ [tool.ruff.lint.per-file-ignores]
+ "tests/**/*.py" = ["ANN"]
+
+ [tool.ruff.format]
+ docstring-code-format = true