Skip to content

Strengthen test typing - remove all test-related mypy overrides and ruff ANN001 ignore #140

Merged
seapagan merged 6 commits intomainfrom
feature/test-mypy-typing-hardening
Feb 26, 2026
Merged

Strengthen test typing - remove all test-related mypy overrides and ruff ANN001 ignore #140
seapagan merged 6 commits intomainfrom
feature/test-mypy-typing-hardening

Conversation

@seapagan
Copy link
Owner

@seapagan seapagan commented Feb 25, 2026

Summary

  • remove remaining test-specific mypy overrides and make tests pass mypy --strict
  • add/strengthen type annotations across test fixtures and test functions
  • resolve dynamic-attribute typing in ORM/TUI tests with targeted casts where runtime attributes are injected dynamically
  • remove the ANN001 Ruff ignore for tests/**/*.py
  • add a TODO item to track user-facing library typing improvements for dynamic ORM relationship APIs

Rationale

This brings strict typing standards to the test suite without reintroducing broad suppressions, and keeps runtime behavior unchanged. It also tightens lint policy by dropping the no-longer-needed ANN001 ignore for tests.

Checks Run

  • poe ruff (passes)
  • poe mypy (passes: no issues in 102 source files)
  • poe test (passes: 1005 passed, 1 skipped)

Summary by CodeRabbit

  • Refactor

    • Improved library type hints for ORM relationship APIs to reduce casts needed in application code.
  • Tests

    • Strengthened test suite with widespread type annotations and small test refinements for clearer static analysis.
  • Chores

    • Adjusted linting and type-checking configuration to align with the enhanced typing approach.

@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9332233 and 17104c9.

📒 Files selected for processing (2)
  • pyproject.toml
  • tests/test_query.py
💤 Files with no reviewable changes (1)
  • pyproject.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_query.py

📝 Walkthrough

Walkthrough

This PR adds short-term typing notes and widespread type-hint improvements across the test suite and configuration: tests now annotate fixtures (SqliterDB, MockerFixture, Path, pytest.LogCaptureFixture, etc.) and use TYPE_CHECKING casts; pyproject.toml had mypy overrides removed and ANN001 removed from per-file ruff ignores. No behavioural changes.

Changes

Cohort / File(s) Summary
Configuration & Notes
TODO.md, pyproject.toml
Added a TODO entry about typing upgrades; removed ANN001 from ruff per-file ignores and removed the [tool.mypy.overrides] block.
Test bootstrap
tests/conftest.py
Added type annotations to pytest_configure, not_raises, and temp_db_path (pytest.Config, type[BaseException], Path) and TYPE_CHECKING imports.
Core DB & Query tests
tests/test_sqliter.py, tests/test_query.py, tests/test_bulk_update.py, tests/test_order_method.py, tests/test_aggregates.py
Annotated many test parameters with SqliterDB and MockerFixture; updated temp_db_path/tmp_path typing where relevant. Changes are signatures-only.
ORM / Relationship tests
tests/test_foreign_keys_orm.py, tests/test_m2m.py, tests/test_prefetch_related.py, tests/test_orm_fields.py
Introduced Any/cast usages and getattr/cast indirection for reverse FK/M2M descriptors and prefetched results to satisfy type-checkers; no runtime logic changes.
Cache, transactions & context
tests/test_cache.py, tests/test_transaction_rollback.py, tests/test_context_manager.py
Annotated tmp_path as Path, adjusted SqliterDB initialisations in tests to use string paths where needed; added TYPE_CHECKING imports and MockerFixture typing.
Timestamps, dates & optional fields
tests/test_dates.py, tests/test_timestamps.py, tests/test_optional_fields.py
Added SqliterDB / MockerFixture type hints and one additional test assertion; signature-only typing changes.
Logging, properties & errors
tests/test_debug_logging.py, tests/test_properties.py, tests/test_execeptions.py, tests/test_foreign_keys.py, tests/test_drop_table.py, tests/test_unique.py
Annotated caplog with pytest.LogCaptureFixture, added MockerFixture typings and minor test-scoped mock variable changes; no behavioural modifications.
TUI tests
tests/tui/... (e.g., tests/tui/test_app.py, tests/tui/test_demo_registry.py, tests/tui/test_init.py, tests/tui/test_main.py, tests/tui/unit/*, tests/tui/widgets/*)
Added TYPE_CHECKING blocks, annotated fixtures (Demo, ModuleType, reset_demo_registry: None, MockerFixture), and used casts where needed; purely typing/formatting changes across TUI tests.
Misc test tweaks
many tests/* files
General formatting and signature cleanup across many test files; no production API changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

enhancement

Poem

🐰
I hopped through tests with tiny paws,
Sprinkled hints and fixed the flaws.
SqliterDB and MockerFixture gleam,
Casts and TYPE_CHECKING — a typing dream.
Nose wiggles: tests now type-scheme clean!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: strengthening test typing and removing mypy overrides and ruff ANN001 ignores, which aligns with the comprehensive test annotation updates and configuration removals throughout the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 99.18% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/test-mypy-typing-hardening

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codacy-production
Copy link

codacy-production bot commented Feb 25, 2026

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.00% (target: -1.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (78be73d) 4869 4869 100.00%
Head commit (17104c9) 4869 (+0) 4869 (+0) 100.00% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#140) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@seapagan seapagan changed the title Strengthen test typing and remove ANN001 test ignore Strengthen test typing remove all test-related mypy overrides and ruff ANN001 override Feb 25, 2026
@seapagan seapagan changed the title Strengthen test typing remove all test-related mypy overrides and ruff ANN001 override Strengthen test typing remove all test-related mypy overrides and ruff ANN001 ignore Feb 25, 2026
@seapagan seapagan self-assigned this Feb 25, 2026
@seapagan seapagan marked this pull request as ready for review February 25, 2026 19:49
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
pyproject.toml (1)

157-159: Consider deleting the commented-out [tool.mypy.overrides] block rather than keeping it.

Commented-out TOML config has no effect and can mislead future readers into thinking the overrides are temporarily disabled. Since this PR permanently removes the suppression, the dead config is better removed entirely.

🗑️ Proposed change
-#[[tool.mypy.overrides]]
-#disable_error_code = ["method-assign", "no-untyped-def", "attr-defined"]
-#module = "tests.*"
-
 [tool.pytest.ini_options]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pyproject.toml` around lines 157 - 159, Remove the commented-out
[tool.mypy.overrides] block from pyproject.toml (the three commented lines
starting with #[[tool.mypy.overrides]] and the following
disable_error_code/module lines) so the dead TOML config is deleted rather than
left commented out; simply delete those three comment lines referencing the
overrides to avoid misleading future readers.
tests/test_orm_fields.py (1)

201-201: Minor: the "Union" branch in the set is unreachable given the skipif guard.

The test is already gated on sys.version_info >= (3, 10), so type(pep604_union).__name__ will always be "UnionType" inside this test. The "Union" entry is dead code. This has no impact on correctness, but if future readers see it they may wonder whether the test can actually produce a typing.Union object.

🔍 Simplified assertion
-    assert type(pep604_union).__name__ in {"UnionType", "Union"}
+    assert type(pep604_union).__name__ == "UnionType"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_orm_fields.py` at line 201, The assertion uses an unreachable
branch: update the check on pep604_union to only expect "UnionType" (e.g.,
replace assert type(pep604_union).__name__ in {"UnionType", "Union"} with assert
type(pep604_union).__name__ == "UnionType") so the test matches the
sys.version_info >= (3, 10) guard; refer to the existing pep604_union variable
and the assert expression to locate and change the assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/test_query.py`:
- Line 191: The method fetch_last_multiple_results should be renamed to include
the pytest discovery prefix — change its name to
test_fetch_last_multiple_results (update any internal references or calls to
this method if present) so pytest will discover and run it; ensure the function
signature and parameters (db_mock: SqliterDB) remain unchanged.

---

Nitpick comments:
In `@pyproject.toml`:
- Around line 157-159: Remove the commented-out [tool.mypy.overrides] block from
pyproject.toml (the three commented lines starting with #[[tool.mypy.overrides]]
and the following disable_error_code/module lines) so the dead TOML config is
deleted rather than left commented out; simply delete those three comment lines
referencing the overrides to avoid misleading future readers.

In `@tests/test_orm_fields.py`:
- Line 201: The assertion uses an unreachable branch: update the check on
pep604_union to only expect "UnionType" (e.g., replace assert
type(pep604_union).__name__ in {"UnionType", "Union"} with assert
type(pep604_union).__name__ == "UnionType") so the test matches the
sys.version_info >= (3, 10) guard; refer to the existing pep604_union variable
and the assert expression to locate and change the assertion.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 78be73d and 9332233.

📒 Files selected for processing (31)
  • TODO.md
  • pyproject.toml
  • tests/conftest.py
  • tests/test_advanced_filters.py
  • tests/test_aggregates.py
  • tests/test_bulk_update.py
  • tests/test_cache.py
  • tests/test_context_manager.py
  • tests/test_dates.py
  • tests/test_debug_logging.py
  • tests/test_drop_table.py
  • tests/test_execeptions.py
  • tests/test_foreign_keys.py
  • tests/test_foreign_keys_orm.py
  • tests/test_m2m.py
  • tests/test_optional_fields.py
  • tests/test_order_method.py
  • tests/test_orm_fields.py
  • tests/test_prefetch_related.py
  • tests/test_properties.py
  • tests/test_query.py
  • tests/test_sqliter.py
  • tests/test_timestamps.py
  • tests/test_transaction_rollback.py
  • tests/test_unique.py
  • tests/tui/test_app.py
  • tests/tui/test_demo_registry.py
  • tests/tui/test_init.py
  • tests/tui/test_main.py
  • tests/tui/unit/test_demos_others.py
  • tests/tui/widgets/test_demo_list.py

@seapagan seapagan merged commit ee09238 into main Feb 26, 2026
15 checks passed
@seapagan seapagan deleted the feature/test-mypy-typing-hardening branch February 26, 2026 18:44
@seapagan seapagan changed the title Strengthen test typing remove all test-related mypy overrides and ruff ANN001 ignore Strengthen test typing - remove all test-related mypy overrides and ruff ANN001 ignore Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant