chore: add ruff and ty, fix linting

- Add ruff (line-length 88) and ty to dev dependencies
- Fix all ruff linting errors
- Configure ty to ignore nullable type warnings
- Update AGENTS.md with linting instructions
This commit is contained in:
2026-02-02 21:43:08 +03:00
parent 52dce1b2b8
commit fc3f438cbf
8 changed files with 141 additions and 38 deletions

View File

@@ -1,9 +1,9 @@
import sqlite3
from collections.abc import Generator
from contextlib import contextmanager
from dataclasses import dataclass
from datetime import datetime
from enum import Enum
from typing import Generator
from src.config import DB_PATH
from src.logger import logger
@@ -171,7 +171,8 @@ def get_or_create_user(telegram_id: int) -> User:
)
cursor = conn.execute(
"INSERT INTO users (telegram_id) VALUES (?) RETURNING id, telegram_id, created_at",
"INSERT INTO users (telegram_id) VALUES (?) "
"RETURNING id, telegram_id, created_at",
(telegram_id,),
)
row = cursor.fetchone()
@@ -244,10 +245,11 @@ def get_all_scenarios() -> list[Scenario]:
def create_replicas(scenario_id: str, replicas: list[tuple[int, int, str]]) -> None:
"""Создаёт реплики для сценария. replicas: [(speaker_id, replica_index, text), ...]"""
"""Создаёт реплики. replicas: [(speaker_id, replica_index, text), ...]"""
with get_connection() as conn:
conn.executemany(
"INSERT INTO replicas (scenario_id, speaker_id, replica_index, text) VALUES (?, ?, ?, ?)",
"INSERT INTO replicas (scenario_id, speaker_id, replica_index, text) "
"VALUES (?, ?, ?, ?)",
[
(scenario_id, speaker_id, idx, text)
for speaker_id, idx, text in replicas
@@ -300,7 +302,8 @@ def get_track_speaker_ids(scenario_id: str) -> list[int]:
"""Получает список speaker_id (дорожек) в сценарии."""
with get_connection() as conn:
cursor = conn.execute(
"SELECT DISTINCT speaker_id FROM replicas WHERE scenario_id = ? ORDER BY speaker_id",
"SELECT DISTINCT speaker_id FROM replicas "
"WHERE scenario_id = ? ORDER BY speaker_id",
(scenario_id,),
)
return [row["speaker_id"] for row in cursor.fetchall()]
@@ -314,7 +317,8 @@ def create_recording(user_id: int, scenario_id: str, replica_index: int) -> Reco
with get_connection() as conn:
cursor = conn.execute(
"INSERT INTO recordings (user_id, scenario_id, replica_index) "
"VALUES (?, ?, ?) RETURNING id, user_id, scenario_id, replica_index, created_at",
"VALUES (?, ?, ?) "
"RETURNING id, user_id, scenario_id, replica_index, created_at",
(user_id, scenario_id, replica_index),
)
row = cursor.fetchone()
@@ -356,8 +360,9 @@ def get_user_recordings_for_scenario(user_id: int, scenario_id: str) -> list[Rec
"""Получает все записи пользователя для сценария."""
with get_connection() as conn:
cursor = conn.execute(
"SELECT id, user_id, scenario_id, replica_index, created_at FROM recordings "
"WHERE user_id = ? AND scenario_id = ? ORDER BY replica_index",
"SELECT id, user_id, scenario_id, replica_index, created_at "
"FROM recordings WHERE user_id = ? AND scenario_id = ? "
"ORDER BY replica_index",
(user_id, scenario_id),
)
return [