Repository navigation
fix(devshell): stop Nix mypy shadowing the uv.lock-pinned version - #3119
Conversation
Problem The Nix devshell listed `mypy` (a Python-library package) directly in `devShells.default.buildInputs`. mkShell's Python setup hooks add such packages' site-packages to PYTHONPATH, and PYTHONPATH entries are consulted before a venv's own site-packages when Python builds sys.path. So `.venv/bin/mypy` (and any `uv run mypy`) silently ran the Nix-provided mypy 1.20.1 instead of the uv.lock-pinned 2.3.0, even though `.venv` had the correct version installed all along. This let 2.3.0-only strict findings pass locally while CircleCI's bare-Docker quick-gate (no Nix PYTHONPATH injection) failed on the same code, exactly as PR #3077 hit and fixed for polylogue/ itself. Widening the check to the full mypy `files` config (polylogue, tests, devtools — CircleCI checks polylogue/ only) surfaced two further findings CI never covered: a real-mypy narrowing quirk on a tuple-set membership check in test_envelope.py, and a tautological assertion in test_contract_suite.py already implied by the preceding line. Solution - Drop `mypy` from the devshell's buildInputs; uv/`.venv` is already the sole mypy provider via the `dev` extra, so nothing needs it. - Bind the narrowed tuple element to an explicit `str` local in test_envelope.py so mypy 2.3.0 stops inferring an overly narrow literal type across the two sibling `if` checks. - Drop the redundant `!= "exact"` assertion in test_contract_suite.py (already entailed by the preceding `in {"priced", "partial"}` check). - Ignore `.dmypy.json`, the dmypy daemon state file the working `dmypy` invocation now actually produces at the repo root. Verification - `nix develop --command bash -c 'python3 -c "import mypy; print(mypy.__file__, mypy.__version__)"'` → resolves to `.venv/.../mypy` at 2.3.0 (was the Nix store's 1.20.1). - `nix develop --command uv run mypy polylogue/` → clean (matches CircleCI, which already fixed its 3 findings via #3077). - `nix develop --command devtools verify --quick` → 17/17 steps green, exit_code 0 (previously failed on the two findings above once mypy ran at the correct version). - `devtools test tests/unit/coordination/test_envelope.py tests/unit/cost/test_contract_suite.py` → 40 passed, 1 pre-existing failure unrelated to this change (`KeyError: 'cost_outlook'` in `test_mcp_cost_outlook_tool_uses_shared_envelope`, reproduces identically with these edits stashed out; MCP six-tool-cutover registry drift from #3095, not touched here). Ref polylogue-i0ep
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 28 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
The Nix devshell's
mypyentry inbuildInputssilently shadowed theuv.lock-pinned mypy 2.3.0 with the Nix store's 1.20.1, hiding real
strict-mypy findings locally that CircleCI's bare-Docker quick-gate
would catch.
Problem
devShells.default.buildInputslistedmypydirectly (a Pythonlibrary package). mkShell's Python setup hooks add such packages'
site-packages to
PYTHONPATH, andPYTHONPATHentries are consultedbefore a venv's own site-packages when Python builds
sys.path. So.venv/bin/mypy(and anyuv run mypy) ran the Nix-provided 1.20.1instead of the correctly-installed 2.3.0 in
.venv, even inside anactivated devshell.
This is exactly the class of drift PR #3077 hit and fixed for
polylogue/on CircleCI: findings invisible locally, red on CI.Running the real 2.3.0 against the full
[tool.mypy] filesconfig(
polylogue,tests/**,devtools/**— CircleCI checkspolylogue/only) surfaced two further findings CI has never covered:
tests/unit/coordination/test_envelope.py:215— a real mypynarrowing limitation: after
key in {tuple_a, tuple_b, tuple_c}narrows a tuple, mypy only tracks one alternative's literal type for
a later subscript (
key[1]), so a subsequent siblingif key[1] == "gate":is flagged as comparing non-overlapping literals eventhough the runtime behavior is correct.
tests/unit/cost/test_contract_suite.py:203— a tautologicalassertion (
!= "exact") already entailed by the precedingin {"priced", "partial"}check on the same narrowed value.Solution
mypyfrom the devshell'sbuildInputs..venv(viauv sync --extra dev) is already the sole mypy provider; the Nixcopy served no purpose except colliding with it.
test_envelope.py: bind the tuple element to an explicitstrlocal (
subcommand: str = key[1]) before comparing, which stopsmypy from carrying an overly narrow literal type across the two
sibling checks. No runtime behavior change.
test_contract_suite.py: delete the redundant assertion; thepreceding line already proves it.
.gitignore: add.dmypy.json, the dmypy daemon state file that anow-actually-working
dmypyinvocation creates at the repo root(alongside the existing
.mypy_cache/entry).Verification
nix develop --command bash -c 'python3 -c "import mypy; print(mypy.__file__, mypy.__version__)"'→ resolves to
.venv/.../mypyat 2.3.0 (was the Nix store's 1.20.1before this change).
nix develop --command uv run mypy polylogue/→ clean (matchesCircleCI, whose 3 original findings were already fixed by fix(ci): satisfy Circle strict mypy checks #3077).
nix develop --command devtools verify --quick→ 17/17 steps green,exit_code: 0.devtools test tests/unit/coordination/test_envelope.py tests/unit/cost/test_contract_suite.py→ 40 passed. 1 pre-existing failure unrelated to this change
(
KeyError: 'cost_outlook'intest_mcp_cost_outlook_tool_uses_shared_envelope) reproducesidentically with these edits stashed out — MCP six-tool-cutover
registry drift from fix(mcp): harden six-tool cutover — session correlation, status(operation), SessionStart preamble #3095, not touched by this PR.
Ref polylogue-i0ep