Skip to content

Commit 8b35efe

Browse files
authored
👷 Run mypy by pre-commit (#2169)
1 parent 7af1d80 commit 8b35efe

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ repos:
4040
language: unsupported
4141
types: [python]
4242

43+
- id: local-mypy
44+
name: mypy check
45+
entry: uv run mypy backend/app
46+
require_serial: true
47+
language: unsupported
48+
pass_filenames: false
49+
4350
- id: generate-frontend-sdk
4451
name: Generate Frontend SDK
4552
entry: bash ./scripts/generate-client.sh

backend/app/alembic/env.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# Interpret the config file for Python logging.
1212
# This line sets up loggers basically.
13+
assert config.config_file_name is not None
1314
fileConfig(config.config_file_name)
1415

1516
# add your model's MetaData object here

backend/app/api/routes/items.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any
33

44
from fastapi import APIRouter, HTTPException
5-
from sqlmodel import func, select
5+
from sqlmodel import col, func, select
66

77
from app.api.deps import CurrentUser, SessionDep
88
from app.models import Item, ItemCreate, ItemPublic, ItemsPublic, ItemUpdate, Message
@@ -22,7 +22,7 @@ def read_items(
2222
count_statement = select(func.count()).select_from(Item)
2323
count = session.exec(count_statement).one()
2424
statement = (
25-
select(Item).order_by(Item.created_at.desc()).offset(skip).limit(limit)
25+
select(Item).order_by(col(Item.created_at).desc()).offset(skip).limit(limit)
2626
)
2727
items = session.exec(statement).all()
2828
else:
@@ -35,7 +35,7 @@ def read_items(
3535
statement = (
3636
select(Item)
3737
.where(Item.owner_id == current_user.id)
38-
.order_by(Item.created_at.desc())
38+
.order_by(col(Item.created_at).desc())
3939
.offset(skip)
4040
.limit(limit)
4141
)

backend/app/api/routes/users.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def read_users(session: SessionDep, skip: int = 0, limit: int = 100) -> Any:
4242
count_statement = select(func.count()).select_from(User)
4343
count = session.exec(count_statement).one()
4444

45-
statement = select(User).order_by(User.created_at.desc()).offset(skip).limit(limit)
45+
statement = (
46+
select(User).order_by(col(User.created_at).desc()).offset(skip).limit(limit)
47+
)
4648
users = session.exec(statement).all()
4749

4850
return UsersPublic(data=users, count=count)
@@ -223,7 +225,7 @@ def delete_user(
223225
status_code=403, detail="Super users are not allowed to delete themselves"
224226
)
225227
statement = delete(Item).where(col(Item.owner_id) == user_id)
226-
session.exec(statement) # type: ignore
228+
session.exec(statement)
227229
session.delete(user)
228230
session.commit()
229231
return Message(message="User deleted successfully")

0 commit comments

Comments
 (0)