Refactor: 445 # type: ignore suppressions in infrastructure/database/repositories.py mask type errors #10292

Open
opened 2026-04-18 08:06:55 +00:00 by HAL9000 · 0 comments
Owner

Metadata

  • Commit message: refactor(infrastructure): remove type: ignore suppressions from repositories.py by fixing underlying type errors
  • Branch name: feature/refactor-remove-type-ignore-repositories

Background and Context

src/cleveragents/infrastructure/database/repositories.py contains 445 # type: ignore comments, making it the single largest source of type-safety suppression in the codebase. The CONTRIBUTING.md explicitly prohibits # type: ignore comments: "⚠️ No # type: ignore comments anywhere" and "⚠️ Zero tolerance for # type: ignore — reject any PR that adds one".

This was detected by an automated architecture guard scan on 2026-04-18.

The file is 6,086 lines long and the suppressions are pervasive — nearly every ORM model attribute assignment uses # type: ignore[assignment] or # type: ignore[union-attr]. This indicates a systematic mismatch between the SQLAlchemy ORM model type annotations and the domain entity types being mapped.

Additional # type: ignore occurrences in other files (total: 445 in repositories.py alone):

  • langgraph/bridge.pyimport rx # type: ignore (missing type stubs)
  • langgraph/graph.py, state.pyrx.core imports with # type: ignore[attr-defined]
  • reactive/application.py, route_bridge.py, stream_router.pyrx scheduler imports
  • tool/builtins/subplan_tool.py — one # type: ignore[list-item]

Current Behavior

The repositories.py file suppresses type errors on virtually every ORM model attribute assignment:

# Example pattern repeated ~200 times:
row.namespace = project.namespace  # type: ignore[assignment]
row.description = project.description  # type: ignore[assignment]
row.updated_at = datetime.now(tz=UTC).isoformat()  # type: ignore[assignment]

# And on relationship collections:
row.project_links_rel.clear()  # type: ignore[union-attr]
row.arguments_rel.append(...)  # type: ignore[union-attr]

This means Pyright is unable to verify the correctness of the entire repository layer, which is the critical persistence boundary of the application.

Expected Behavior

All # type: ignore comments must be removed. The underlying type errors must be fixed by:

  1. Properly annotating SQLAlchemy ORM model attributes with Mapped[T] types (SQLAlchemy 2.x style)
  2. Using proper type stubs or py.typed markers for the rx (RxPY) library
  3. Fixing any genuine type mismatches between domain entities and ORM models

Acceptance Criteria

  • Zero # type: ignore comments in src/cleveragents/infrastructure/database/repositories.py
  • Zero # type: ignore comments in src/cleveragents/langgraph/ files
  • Zero # type: ignore comments in src/cleveragents/reactive/ files
  • Zero # type: ignore comments anywhere in src/cleveragents/
  • nox -s typecheck passes with zero errors after removal
  • All existing Behave scenarios continue to pass
  • Coverage remains ≥ 97%

Supporting Information

  • Scan date: 2026-04-18
  • Scan tool: Architecture Guard Worker (automated)
  • Primary file: src/cleveragents/infrastructure/database/repositories.py (6,086 lines, 445 suppressions)
  • CONTRIBUTING.md rule: "⚠️ No # type: ignore comments anywhere"
  • Root cause: SQLAlchemy ORM models likely use untyped Column() declarations instead of Mapped[T] (SQLAlchemy 2.x typed API)
  • Secondary cause: rx (RxPY) library lacks type stubs — solution is to add a typings/rx/ stub or use types-rx if available

Subtasks

  • Audit all # type: ignore occurrences in src/cleveragents/ and categorize by root cause
  • Migrate SQLAlchemy ORM models in infrastructure/database/models.py to use Mapped[T] typed columns (SQLAlchemy 2.x style)
  • Update repositories.py to use properly typed ORM model attributes — removing all # type: ignore[assignment] suppressions
  • Fix # type: ignore[union-attr] suppressions by ensuring relationship attributes are properly typed as Mapped[list[T]]
  • Add type stubs for rx (RxPY) library in typings/rx/ or find a typed alternative
  • Remove all # type: ignore comments from langgraph/ and reactive/ files
  • Run nox -s typecheck and fix all newly surfaced type errors
  • Tests (Behave): Verify all repository scenarios still pass after type annotation changes
  • Verify coverage ≥ 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • grep -r "# type: ignore" src/cleveragents/ returns zero results.
  • nox -s typecheck passes with zero errors.
  • A Git commit is created where the first line matches the Commit Message in Metadata exactly, followed by a blank line, then additional details.
  • The commit is pushed to the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Automated by Architecture Guard Worker — scan date 2026-04-18


Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit message:** `refactor(infrastructure): remove type: ignore suppressions from repositories.py by fixing underlying type errors` - **Branch name:** `feature/refactor-remove-type-ignore-repositories` ## Background and Context `src/cleveragents/infrastructure/database/repositories.py` contains **445 `# type: ignore` comments**, making it the single largest source of type-safety suppression in the codebase. The CONTRIBUTING.md explicitly prohibits `# type: ignore` comments: *"⚠️ No # type: ignore comments anywhere"* and *"⚠️ Zero tolerance for # type: ignore — reject any PR that adds one"*. This was detected by an automated architecture guard scan on 2026-04-18. The file is 6,086 lines long and the suppressions are pervasive — nearly every ORM model attribute assignment uses `# type: ignore[assignment]` or `# type: ignore[union-attr]`. This indicates a systematic mismatch between the SQLAlchemy ORM model type annotations and the domain entity types being mapped. **Additional `# type: ignore` occurrences in other files (total: 445 in repositories.py alone):** - `langgraph/bridge.py` — `import rx # type: ignore` (missing type stubs) - `langgraph/graph.py`, `state.py` — `rx.core` imports with `# type: ignore[attr-defined]` - `reactive/application.py`, `route_bridge.py`, `stream_router.py` — `rx` scheduler imports - `tool/builtins/subplan_tool.py` — one `# type: ignore[list-item]` ## Current Behavior The `repositories.py` file suppresses type errors on virtually every ORM model attribute assignment: ```python # Example pattern repeated ~200 times: row.namespace = project.namespace # type: ignore[assignment] row.description = project.description # type: ignore[assignment] row.updated_at = datetime.now(tz=UTC).isoformat() # type: ignore[assignment] # And on relationship collections: row.project_links_rel.clear() # type: ignore[union-attr] row.arguments_rel.append(...) # type: ignore[union-attr] ``` This means Pyright is unable to verify the correctness of the entire repository layer, which is the critical persistence boundary of the application. ## Expected Behavior All `# type: ignore` comments must be removed. The underlying type errors must be fixed by: 1. Properly annotating SQLAlchemy ORM model attributes with `Mapped[T]` types (SQLAlchemy 2.x style) 2. Using proper type stubs or `py.typed` markers for the `rx` (RxPY) library 3. Fixing any genuine type mismatches between domain entities and ORM models ## Acceptance Criteria - [ ] Zero `# type: ignore` comments in `src/cleveragents/infrastructure/database/repositories.py` - [ ] Zero `# type: ignore` comments in `src/cleveragents/langgraph/` files - [ ] Zero `# type: ignore` comments in `src/cleveragents/reactive/` files - [ ] Zero `# type: ignore` comments anywhere in `src/cleveragents/` - [ ] `nox -s typecheck` passes with zero errors after removal - [ ] All existing Behave scenarios continue to pass - [ ] Coverage remains ≥ 97% ## Supporting Information - Scan date: 2026-04-18 - Scan tool: Architecture Guard Worker (automated) - Primary file: `src/cleveragents/infrastructure/database/repositories.py` (6,086 lines, 445 suppressions) - CONTRIBUTING.md rule: *"⚠️ No # type: ignore comments anywhere"* - Root cause: SQLAlchemy ORM models likely use untyped `Column()` declarations instead of `Mapped[T]` (SQLAlchemy 2.x typed API) - Secondary cause: `rx` (RxPY) library lacks type stubs — solution is to add a `typings/rx/` stub or use `types-rx` if available ## Subtasks - [ ] Audit all `# type: ignore` occurrences in `src/cleveragents/` and categorize by root cause - [ ] Migrate SQLAlchemy ORM models in `infrastructure/database/models.py` to use `Mapped[T]` typed columns (SQLAlchemy 2.x style) - [ ] Update `repositories.py` to use properly typed ORM model attributes — removing all `# type: ignore[assignment]` suppressions - [ ] Fix `# type: ignore[union-attr]` suppressions by ensuring relationship attributes are properly typed as `Mapped[list[T]]` - [ ] Add type stubs for `rx` (RxPY) library in `typings/rx/` or find a typed alternative - [ ] Remove all `# type: ignore` comments from `langgraph/` and `reactive/` files - [ ] Run `nox -s typecheck` and fix all newly surfaced type errors - [ ] Tests (Behave): Verify all repository scenarios still pass after type annotation changes - [ ] Verify coverage ≥ 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - `grep -r "# type: ignore" src/cleveragents/` returns zero results. - `nox -s typecheck` passes with zero errors. - A Git commit is created where the first line matches the Commit Message in Metadata exactly, followed by a blank line, then additional details. - The commit is pushed to the branch matching the Branch in Metadata exactly. - The commit is submitted as a pull request to `master`, reviewed, and merged before this issue is marked done. --- *Automated by Architecture Guard Worker — scan date 2026-04-18* --- **Automated by CleverAgents Bot** Agent: new-issue-creator
Sign in to join this conversation.
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
cleveragents/cleveragents-core#10292
No description provided.