Skip to content

Type-check and ship types for cdc/ai/sqlalchemy/django - #12

Merged
felipeg48 merged 2 commits into
mainfrom
feature/py-typed-mypy-gate
Nov 25, 2026
Merged

felipeg48 merged 2 commits into
mainfrom
feature/py-typed-mypy-gate

Conversation

@felipeg48

Copy link
Copy Markdown
Contributor

What

Closes the type-safety gap for the four secondary packages (cockroachdb-cdc, cockroachdb-ai, cockroachdb-sqlalchemy, cockroachdb-django), which previously shipped no py.typed marker and were excluded from the strict mypy gate in CI — so downstream consumers got no types for them.

Changes

  1. py.typed markers added to all four packages (src/cockroachdb/{cdc,ai,sqla,django}/py.typed). Hatchling's packages = ["src/cockroachdb"] auto-includes the marker in the wheel (verified by building the django wheel) — no pyproject.toml change needed, matching the existing four typed packages.
  2. CI: extended the uv run mypy ... invocation in .github/workflows/ci.yml to also check the four /src dirs.
  3. Real strict fixes (no loosening of mypy config): added missing annotations, generic type args (TypeEngine[Any], dict[str, Any], list[Any]), and fixed Any returns.
    • Notable latent bug: core RegionContext had set() but no reset() classmethod, yet sqla RegionalSession.execute() called RegionContext.reset(token) in its finally — a runtime AttributeError. Added reset().
    • sqla/events.py now re-exports RegionContext/FollowerReadContext via __all__ (strict no_implicit_reexport).
  4. One narrow override: [[tool.mypy.overrides]] module = ["django.*"] ignore_missing_imports = true — Django ships no py.typed and no bundled stubs. Scoped to django.* only; strictness is unchanged everywhere else. Framework-override signature/misc frictions (SQLAlchemy/Django base classes) use targeted per-line # type: ignore[...].

Verification (local)

  • mypy strict over all 8 package /src dirs: Success, 61 files
  • ruff format --check + ruff check: clean
  • pytest: 590 passed, 3 skipped

No version bumps (lead handles release).

The four secondary packages shipped no py.typed marker and were excluded
from the strict mypy gate in CI, so consumers got no types for them.

- Add py.typed to cockroachdb-{cdc,ai,sqlalchemy,django}; hatchling's
  packages=["src/cockroachdb"] auto-includes it in the wheel (no
  pyproject change needed, matching the existing four packages).
- Extend the ci.yml mypy invocation to cover the four /src dirs.
- Fix real strict violations surfaced by the newly-gated source:
  missing annotations, generic type args (TypeEngine[Any], dict[str, Any],
  list[Any]), and Any returns. Notably: core RegionContext had no reset()
  classmethod though sqla RegionalSession.execute() called it (latent
  AttributeError); added it. events.py now re-exports Region/FollowerRead
  contexts via __all__.
- Add a narrow [[tool.mypy.overrides]] ignore_missing_imports for django.*
  only (Django ships no py.typed); strictness is unchanged elsewhere.

mypy (61 files), ruff, and pytest (590 passed) all green locally.
- cockroachdb-core 0.2.0 -> 0.3.0 (public RegionContext.reset())
- cockroachdb-sqlalchemy 0.2.0 -> 0.3.0
- cockroachdb-django 0.2.0 -> 0.3.0
- cockroachdb-cdc 0.1.1 -> 0.2.0
- cockroachdb-ai 0.1.2 -> 0.2.0
@felipeg48
felipeg48 merged commit 4a11c35 into main Nov 25, 2026
3 checks passed
@felipeg48
felipeg48 deleted the feature/py-typed-mypy-gate branch November 25, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant