Skip to content

Commit 2fdd62c

Browse files
👷 Add ty to precommit (#2227)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 8bf0025 commit 2fdd62c

File tree

10 files changed

+47
-6
lines changed

10 files changed

+47
-6
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ repos:
4747
language: unsupported
4848
pass_filenames: false
4949

50+
- id: local-ty
51+
name: ty check
52+
entry: uv run ty check backend/app
53+
require_serial: true
54+
language: unsupported
55+
pass_filenames: false
56+
5057
- id: generate-frontend-sdk
5158
name: Generate Frontend SDK
5259
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
@@ -63,6 +63,7 @@ def run_migrations_online():
6363
6464
"""
6565
configuration = config.get_section(config.config_ini_section)
66+
assert configuration is not None
6667
configuration["sqlalchemy.url"] = get_url()
6768
connectable = engine_from_config(
6869
configuration,

backend/app/alembic/versions/1a31ce608336_add_cascade_delete_relationships.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def upgrade():
2929

3030
def downgrade():
3131
# ### commands auto generated by Alembic - please adjust! ###
32-
op.drop_constraint(None, 'item', type_='foreignkey')
32+
op.drop_constraint('item_owner_id_fkey', 'item', type_='foreignkey')
3333
op.create_foreign_key('item_owner_id_fkey', 'item', 'user', ['owner_id'], ['id'])
3434
op.alter_column('item', 'owner_id',
3535
existing_type=sa.UUID(),

backend/app/api/routes/items.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def read_items(
4141
)
4242
items = session.exec(statement).all()
4343

44-
return ItemsPublic(data=items, count=count)
44+
items_public = [ItemPublic.model_validate(item) for item in items]
45+
return ItemsPublic(data=items_public, count=count)
4546

4647

4748
@router.get("/{id}", response_model=ItemPublic)

backend/app/api/routes/users.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def read_users(session: SessionDep, skip: int = 0, limit: int = 100) -> Any:
4747
)
4848
users = session.exec(statement).all()
4949

50-
return UsersPublic(data=users, count=count)
50+
users_public = [UserPublic.model_validate(user) for user in users]
51+
return UsersPublic(data=users_public, count=count)
5152

5253

5354
@router.post(

backend/app/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class UserRegister(SQLModel):
3131

3232
# Properties to receive via API on update, all are optional
3333
class UserUpdate(UserBase):
34-
email: EmailStr | None = Field(default=None, max_length=255) # type: ignore
34+
email: EmailStr | None = Field(default=None, max_length=255) # type: ignore[assignment]
3535
password: str | None = Field(default=None, min_length=8, max_length=128)
3636

3737

@@ -80,7 +80,7 @@ class ItemCreate(ItemBase):
8080

8181
# Properties to receive on item update
8282
class ItemUpdate(ItemBase):
83-
title: str | None = Field(default=None, min_length=1, max_length=255) # type: ignore
83+
title: str | None = Field(default=None, min_length=1, max_length=255) # type: ignore[assignment]
8484

8585

8686
# Database model, database table inferred from class name

backend/app/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pathlib import Path
55
from typing import Any
66

7-
import emails # type: ignore
7+
import emails # type: ignore[import-untyped]
88
import jwt
99
from jinja2 import Template
1010
from jwt.exceptions import InvalidTokenError

backend/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies = [
2525
dev = [
2626
"pytest<8.0.0,>=7.4.3",
2727
"mypy<2.0.0,>=1.8.0",
28+
"ty>=0.0.25",
2829
"ruff<1.0.0,>=0.2.2",
2930
"prek>=0.2.24,<1.0.0",
3031
"coverage<8.0.0,>=7.4.3",
@@ -75,3 +76,6 @@ sort = "-Cover"
7576

7677
[tool.coverage.html]
7778
show_contexts = true
79+
80+
[tool.ty.terminal]
81+
error-on-warning = true

backend/scripts/lint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ set -e
44
set -x
55

66
mypy app
7+
ty check app
78
ruff check app
89
ruff format app --check

uv.lock

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)