chore(mypy): type database layer (src/ 42 -> 29)#1277
Open
axisrow wants to merge 1 commit into
Open
Conversation
Part of #1133. Typing-only changes, no runtime behavior change: - migrations/connection/pool/repositories.filters: cast() on cursor.fetchall()/execute_fetchall() — aiosqlite stubs declare Iterable[Row], the runtime value is a list - facade.transaction(): bind the asserted connection to a local so the narrowed type stays visible inside the busy-retry lambda - facade.record_rename_event: separate variable for the write cursor (read path returns BufferedCursor, write path aiosqlite.Cursor) - repositories.collection_tasks: add ExportTaskPayload to the _deserialize_payload return union and _serialize_payload param union — both code paths already handle it (parse branch + isinstance tuple) - repositories.messages: explicit None/empty check narrows the setting value before int(); assert sq.id after the not-None pre-filter Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G3ExCZyXkbUpTkRRrQrFA2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #1133 (mypy debt reduction axis). Independent sibling of #1275 (telegram utils) — disjoint files.
mypy delta
python -m mypy src/on this branch: 42 errors -> 29 errors (−13). No new errors in untouched files (verified against per-file baseline).Changes (typing-only, no runtime behavior change)
cast()aroundfetchall()/execute_fetchall()results — aiosqlite stubs declareIterable[Row]while the runtime value is a list;castis a runtime no-op (no copy).dbso the narrowed non-optional type is visible inside the busy-retry lambda (mypy does not propagate attribute narrowing into closures).write_curvariable — the read path returnsBufferedCursor, the write pathaiosqlite.Cursor(which ownslastrowid).ExportTaskPayloadto_deserialize_payloadreturn union and_serialize_payloadparam union — both code paths already handle it at runtime (thetask_kind == EXPORTparse branch and theisinstancetuple); this only aligns annotations with existing code. The interop payloads (interop: новые типы задач + payload-модели (dm_reply/chat_answer/fetch_*) #960DmReplyTaskPayloadetc.) stay excluded per the design note in models.py.is None or == ""narrowing beforeint()(semantically identical to the tuple-membership check);assert sq.id is not Noneinside the chunk loop —validpre-filters None ids two lines above.Verification
ruff check src/ tests/ conftest.py— cleanpython -m mypy src/— 29 errors (was 42), untouched files unchangedpytest tests/repositories/ tests/test_database.py tests/test_database_pool.py tests/test_database_write_lock.py tests/test_migrations.py tests/test_migrations_schema_paths.py— 496 passed🤖 Generated with Claude Code
https://claude.ai/code/session_01G3ExCZyXkbUpTkRRrQrFA2