|
| 1 | +# 01 — Add a blocking `ty` type-check gate (ratcheted) and clean up tooling config |
| 2 | + |
| 3 | +**Priority:** P1 |
| 4 | +**Depends on:** — |
| 5 | +**Unblocks:** 02–07 (the ratchet is how later tickets prove their typing work) |
| 6 | + |
| 7 | +## Problem |
| 8 | + |
| 9 | +The SDK ships `src/codesphere/py.typed` (so downstream type checkers trust our annotations) and |
| 10 | +`.github/copilot-instructions.md` states "Strict type hints required" — but **no type checker |
| 11 | +exists anywhere**: not in dev dependencies, not in `.pre-commit-config.yaml`, not in |
| 12 | +`.github/workflows/ci.yml`. The claim is unenforced, and several annotations in `core/` are |
| 13 | +actively wrong (see ticket 02). |
| 14 | + |
| 15 | +Surrounding tooling config has drifted: |
| 16 | + |
| 17 | +- `ruff.toml` selects only `["F", "E4", "E7", "E9"]` and ignores `E721`/`F841` (unused locals |
| 18 | + pass lint). Its `exclude` list references `src/codesphere_sdk/...` paths that don't exist — |
| 19 | + leftovers from a generated-client era. |
| 20 | +- `pyproject.toml` `[tool.coverage.run]` has `source = ["api", "handler", "tasks"]` |
| 21 | + (pyproject.toml:64) — none of those packages exist, so coverage numbers are unanchored. |
| 22 | + `omit` also lists nonexistent `docs/*` / `scripts/**` roots. |
| 23 | +- `pyproject.toml:13-14,22` declare `aiohttp`, `aiohttp-retry`, and `urllib3` as runtime |
| 24 | + dependencies; `grep -r` over `src/` shows zero imports of any of them (the SDK is pure httpx). |
| 25 | + They bloat installs and imply a retry feature that doesn't exist (see ticket 07). |
| 26 | +- `requires-python = ">=3.12.9"` (pyproject.toml:11) pins an oddly specific patch release, |
| 27 | + excluding 3.12.0–3.12.8 users for no identified reason. |
| 28 | + |
| 29 | +## Approach |
| 30 | + |
| 31 | +Toolchain choice: **`ty`** (Astral) rather than mypy/pyright, to keep type checking and linting |
| 32 | +in the same toolchain family as ruff. ty is pre-1.0: **pin its version** in the dev group and |
| 33 | +expect occasional rule renames on upgrades (note this in a comment next to the pin). |
| 34 | + |
| 35 | +1. **Add ty as a blocking gate with a ratchet.** |
| 36 | + - `uv add --dev ty` (pinned, e.g. `ty==0.0.x`). |
| 37 | + - Configure in `pyproject.toml` under `[tool.ty]`: `src.root = "src"`, error-level rules for |
| 38 | + the strictness-relevant checks (unresolved attributes, invalid assignments, invalid |
| 39 | + argument types, missing/implicit `Any` where ty supports it). |
| 40 | + - **Ratchet:** exclude the paths that cannot pass until later tickets land, via |
| 41 | + `[[tool.ty.overrides]]` (or `src.exclude` if the pinned ty version's override granularity |
| 42 | + is insufficient): |
| 43 | + - `src/codesphere/core/**` and `src/codesphere/resources/**` → removed by tickets 02/04 |
| 44 | + - `src/codesphere/http_client.py`, `src/codesphere/client.py`, `src/codesphere/config.py` → removed by ticket 03 |
| 45 | + Annotate each exclusion with the ticket number that deletes it. |
| 46 | + - CI: add a `typecheck` job to `.github/workflows/ci.yml` running `uv run ty check` |
| 47 | + (blocking). Add the same to `.pre-commit-config.yaml` and a `make typecheck` target. |
| 48 | + |
| 49 | +2. **Broaden ruff.** |
| 50 | + - `select = ["F", "E", "W", "I", "UP", "B", "SIM", "RUF"]`; drop the `F841` and `E721` |
| 51 | + ignores; delete the entire stale `src/codesphere_sdk/*` exclude block. |
| 52 | + - Run `ruff check --fix` + `ruff format`; fix the residue by hand (expect mostly import |
| 53 | + sorting and pyupgrade rewrites like `Optional[X]` → `X | None`). |
| 54 | + |
| 55 | +3. **Fix coverage config.** `[tool.coverage.run] source = ["src/codesphere"]`; prune the |
| 56 | + nonexistent `omit` entries; change the CI pytest invocation from `--cov=.` to rely on the |
| 57 | + config (`--cov`). |
| 58 | + |
| 59 | +4. **Prune dependencies.** Remove `aiohttp`, `aiohttp-retry`, `urllib3` from |
| 60 | + `[project.dependencies]`. While there, grep-verify each remaining runtime dep is actually |
| 61 | + imported (`python-dateutil` is suspect) and remove any that aren't. `uv lock` after. |
| 62 | + |
| 63 | +5. **Relax the Python floor** to `requires-python = ">=3.12"` (align `.python-version` and |
| 64 | + `ruff.toml target-version = "py312"`, which already agree). |
| 65 | + |
| 66 | +## Breaking changes |
| 67 | + |
| 68 | +None. Dependency removals only shrink the install footprint; relaxing `requires-python` widens |
| 69 | +compatibility. |
| 70 | + |
| 71 | +## Acceptance criteria |
| 72 | + |
| 73 | +- [ ] CI fails on any ty error outside the documented ratchet exclusions; `make typecheck` and |
| 74 | + the pre-commit hook run the same command. |
| 75 | +- [ ] Every ratchet exclusion carries a comment naming the ticket that removes it. |
| 76 | +- [ ] `ruff check` passes with the broadened rule set; no `codesphere_sdk` references remain in |
| 77 | + `ruff.toml`. |
| 78 | +- [ ] Coverage output reports lines in `src/codesphere/**` (spot-check the CI coverage comment). |
| 79 | +- [ ] Fresh `uv pip install .` pulls neither aiohttp nor urllib3; `uv.lock` regenerated. |
| 80 | +- [ ] `requires-python = ">=3.12"`. |
0 commit comments