fix(mypy): clear Optional/None + union-type bucket (closes #117 subset) #151

Closed
Mark wants to merge 1 commit from fix/117-mypy-union-opt into main
Owner

Resolves the union-attr / no-any-return / index / operator / dict-item / unreachable / truthy-function / override / no-redef buckets from the #117 audit report (79 -> 0 in scope; 33 files touched).

Scope

  • Adds explicit None checks where runtime None is possible (e.g. session.get() / Optional[...] fields before attribute access).
  • Narrows with assert where the non-None invariant holds.
  • Adjusts module-level type hints and overrides where the existing contract was incorrect (e.g. EvidenceModule.gather signature drift, dict[Any, Any] -> dict[str, Any]).
  • Hoists dict-build annotations out of branches to silence [no-redef].
  • Drops redundant or {} defaults now that Optional is honoured.

Out of scope (separate cards)
attr-defined / assignment / arg-type / redundant-cast / unused-ignore / misc — introduced by later merges (PRs #119, #124, #127).

Verification

  • mypy app/ --config-file ../pyproject.toml reports 0 errors in the Optional/None and union-type-mismatch categories (was 79).
  • ruff check app/ --config ../pyproject.toml is clean.
  • pytest tests/unit shows the same 8 pre-existing failures present on origin/main (case-membership FK, module-metadata fixtures). No new failures.

Files touched (33)

backend/app/modules/dashboard_summary.py
backend/app/modules/email_header_parser.py
backend/app/modules/email_osint.py
backend/app/modules/employee_scraper.py
backend/app/modules/entity_extraction.py
backend/app/modules/entity_linker.py
backend/app/modules/exif_extractor.py
backend/app/modules/local_deep_research.py
backend/app/modules/osint_playbook.py
backend/app/modules/pdf_analyzer.py
backend/app/modules/pdf_report.py
backend/app/modules/pinterest.py
backend/app/modules/reddit.py
backend/app/modules/reverse_image_search.py
backend/app/modules/search_aggregator.py
backend/app/modules/web_scraper.py
backend/app/modules/youtube.py
backend/app/monitoring.py
backend/app/routers/cases.py
backend/app/routers/evidence.py
backend/app/routers/investigations.py
backend/app/routers/queue_api.py
backend/app/services/enrichment.py
backend/app/services/investigations/async_executor.py
backend/app/services/investigations/entity_tools.py
backend/app/services/investigations/llm_entity_extraction.py
backend/app/services/investigations/orchestrator.py
backend/app/services/investigations/orchestrator_enhanced.py
backend/app/services/investigations/pipeline/patterns.py
backend/app/services/investigations/queue_manager.py
backend/app/services/investigations/scheduler.py
backend/app/services/investigations/state_machine.py
backend/app/services/llm/tools/evidence_extraction.py

Closes #117 (subset: union/Optional buckets only).

Resolves the union-attr / no-any-return / index / operator / dict-item / unreachable / truthy-function / override / no-redef buckets from the #117 audit report (79 -> 0 in scope; 33 files touched). **Scope** * Adds explicit None checks where runtime None is possible (e.g. `session.get()` / Optional[...] fields before attribute access). * Narrows with `assert` where the non-None invariant holds. * Adjusts module-level type hints and overrides where the existing contract was incorrect (e.g. `EvidenceModule.gather` signature drift, `dict[Any, Any]` -> `dict[str, Any]`). * Hoists dict-build annotations out of branches to silence [no-redef]. * Drops redundant `or {}` defaults now that Optional is honoured. **Out of scope (separate cards)** attr-defined / assignment / arg-type / redundant-cast / unused-ignore / misc — introduced by later merges (PRs #119, #124, #127). **Verification** * `mypy app/ --config-file ../pyproject.toml` reports 0 errors in the Optional/None and union-type-mismatch categories (was 79). * `ruff check app/ --config ../pyproject.toml` is clean. * `pytest tests/unit` shows the same 8 pre-existing failures present on `origin/main` (case-membership FK, module-metadata fixtures). No new failures. **Files touched (33)** ``` backend/app/modules/dashboard_summary.py backend/app/modules/email_header_parser.py backend/app/modules/email_osint.py backend/app/modules/employee_scraper.py backend/app/modules/entity_extraction.py backend/app/modules/entity_linker.py backend/app/modules/exif_extractor.py backend/app/modules/local_deep_research.py backend/app/modules/osint_playbook.py backend/app/modules/pdf_analyzer.py backend/app/modules/pdf_report.py backend/app/modules/pinterest.py backend/app/modules/reddit.py backend/app/modules/reverse_image_search.py backend/app/modules/search_aggregator.py backend/app/modules/web_scraper.py backend/app/modules/youtube.py backend/app/monitoring.py backend/app/routers/cases.py backend/app/routers/evidence.py backend/app/routers/investigations.py backend/app/routers/queue_api.py backend/app/services/enrichment.py backend/app/services/investigations/async_executor.py backend/app/services/investigations/entity_tools.py backend/app/services/investigations/llm_entity_extraction.py backend/app/services/investigations/orchestrator.py backend/app/services/investigations/orchestrator_enhanced.py backend/app/services/investigations/pipeline/patterns.py backend/app/services/investigations/queue_manager.py backend/app/services/investigations/scheduler.py backend/app/services/investigations/state_machine.py backend/app/services/llm/tools/evidence_extraction.py ``` Closes #117 (subset: union/Optional buckets only).
fix(mypy): clear Optional/None + union-type bucket (closes #117 subset)
Some checks failed
CI / Backend Lint & Format (pull_request) Failing after 6s
CI / Golden Fixture Validation (pull_request) Has been skipped
CI / Backend Tests (pull_request) Has been skipped
CI / Backend Security Tests (pull_request) Has been skipped
Stress Tests / Stress & Pipeline Tests (pull_request) Failing after 8s
Stress Tests / Full Data Pipeline Validation (pull_request) Has been skipped
CI / Frontend Lint (pull_request) Failing after 51s
CI / Frontend Tests (pull_request) Has been skipped
CI / Dependency Security Scan (pull_request) Has been skipped
CI / Frontend E2E Tests (pull_request) Has been skipped
CI / All Checks Passed (pull_request) Failing after 2s
Performance Regression Tests / Performance Regression Detection (pull_request) Failing after 2m12s
Performance Regression Tests / Compare with Baseline (pull_request) Has been skipped
64108fedd3
Resolve all errors in the union-attr / no-any-return / index / operator /
dict-item / unreachable / truthy-function / override / no-redef buckets
from the audit report (79 -> 0). Touched 33 files:

  * add explicit None checks where runtime None is possible
    (e.g. session.get() / Optional[...] fields before attribute access)
  * narrow with assert where the non-None invariant holds
  * adjust module-level type hints and overrides where the existing
    contract was incorrect (e.g. EvidenceModule.gather signature drift,
    dict[Any, Any] -> dict[str, Any])
  * hoist dict-build annotations out of branches to silence [no-redef]
  * drop redundant `or {}` defaults now that Optional is honoured

Out of scope: attr-defined / assignment / arg-type / redundant-cast /
unused-ignore / misc (introduced by later merges, separate cards).

mypy app/ --config-file ../pyproject.toml reports 0 errors in the
Optional/None and union-type-mismatch categories. No runtime behavior
changed on touched paths: ruff check is clean and pytest unit suite
shows the same 8 pre-existing failures present on origin/main.
Mark closed this pull request 2026-09-21 01:09:02 +00:00
Some checks failed
CI / Backend Lint & Format (pull_request) Failing after 6s
CI / Golden Fixture Validation (pull_request) Has been skipped
CI / Backend Tests (pull_request) Has been skipped
CI / Backend Security Tests (pull_request) Has been skipped
Stress Tests / Stress & Pipeline Tests (pull_request) Failing after 8s
Stress Tests / Full Data Pipeline Validation (pull_request) Has been skipped
CI / Frontend Lint (pull_request) Failing after 51s
CI / Frontend Tests (pull_request) Has been skipped
CI / Dependency Security Scan (pull_request) Has been skipped
CI / Frontend E2E Tests (pull_request) Has been skipped
CI / All Checks Passed (pull_request) Failing after 2s
Performance Regression Tests / Performance Regression Detection (pull_request) Failing after 2m12s
Performance Regression Tests / Compare with Baseline (pull_request) Has been skipped

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/osint-hub!151
No description provided.