Repository navigation
chore: check the Python code with mypy --strict and ruff - #99
Merged
Merged
Conversation
mypy --strict covers the worker and the MCP server, and ruff (pycodestyle, pyflakes, bugbear and import order, without the line-length rule) covers them plus the scripts and tests. Both are pinned by hash in requirements-dev.lock, fetched once by py-dev-fetcher and run offline by py-analysis in the MCP job, so the deterministic check requires them. The findings are fixed with annotations and small guards that keep behaviour, and three narrow ignores carry their reason. The worker still imports only the standard library at run time, and the dev files stay out of the dist archive.
# Conflicts: # docs/testing.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #77.
What
The PHP side has had PHPStan at level max; the Python worker and the MCP server had no static analysis. Now:
mypy --strictoverworker/andmcp_server/, andruff checkoverworker/,mcp_server/,scripts/andtests/, with pycodestyle's errors and warnings, pyflakes, bugbear and import order (E,W,F,B,I). Two rules are left out:E501, line length, so long literal data and messages aren't restyled, andB905, since the zips there pair sequences of equal length by construction. Configuration is in a newpyproject.toml, which holds tool settings only. ThemcpSDK is marked third-party so ruff doesn't confuse it withtests/mcp.Pinned versions with one hash per wheel (CPython 3.12, Linux x86_64) in
requirements-dev.lock, fromrequirements-dev.txt(mypy 2.4.0, ruff 0.17.2). A network-enabledpy-dev-fetcherservice fetches them into.cache/once.py-analysisthen installs them, with the MCP server's own locked wheels so mypy can type-check it, into a tmpfs, and runs offline under the hardening block.docs/testing.mdrecords the command that regenerates the lock.A step in
tests.yml'smcpjob, so the requireddeterministiccheck covers it. The same two commands are inAGENTS.md, the check skill,.claude/settings.json(Bash and PowerShell twins), README's test layers anddocs/testing.md..gitattributeskeeps the three new files out of the dist archive.Every finding is fixed with annotations and small guards that keep behaviour: 377 from mypy and 18 from ruff before, none after, plus four ruff findings in measurement scripts that reached main while this branch was open. Three narrow
# type: ignore[assignment]s carry their reasons:Handler.setup'srfilewrapper, which forwards attributes rather than subclassing;handle_one_request's per-request reset ofcommandandpathtoNone;bridge_redact's tuple default, kept rather than a mutable list.One
# noqa: F401keepsMAX_DOCUMENTSimported inscripts/relevance_measure.py: its test reads the limit through the script. The ONNX imports stay inside their functions; mypy is told to ignore onlynumpy,onnxruntimeandtokenizers.Files
pyproject.toml,requirements-dev.txt,requirements-dev.lock.docker/compose.yaml,.github/workflows/tests.yml,.gitattributes,AGENTS.md,.claude/skills/check/SKILL.md,.claude/settings.json,README.md,docs/testing.md,CHANGELOG.md.worker/ai_bridge/{jobs,log,metrics,server,tasks}.py,mcp_server/bridge_mcp/{__main__,index,protocol,tools}.py.scripts/{mcp_evaluate,ner_measure,relevance_measure}.py,tests/mcp/test_index.py,tests/mcp_model_probe.py,tests/model_integration.py,tests/python/{test_jobs,test_server,test_workflows}.py.Checks
The full command block of
AGENTS.md, with the new steps, run as one command on this head (216b6f7: the slice commits merged withmainat 61f9251) in a worktree, PHP 8.5:--profile test config: okpython-tests: Ran 406 tests, OKphp-tests: PASS: 148 PHP contract checks;php -l: no syntax errorsphp-integration: PASS: 192 total PHP checks;integration: PASSmcp-tests: Ran 125 tests, OKpy-dev-fetcher;py-analysis: "All checks passed!" and "Success: no issues found in 11 source files"composer-install: okphp-analysis: [OK] No errors;php-psr18-tests: PASS: 178laravel-tests: 94 checks;symfony-tests: 96 checks;tls-check: 7 + 3 checksThe analysis was seen failing before the fixes: ruff 18, mypy 377 in 9 files. PHP 8.2, 8.3 and 8.4 are left to CI.
Review
Independent read-only review by codex (another model family). It went through every non-test hunk for behaviour hidden in "annotation-only" edits and found each one identical in behaviour:
-O;functools.partialkeeps the bound arguments;ner_measure'sfrom Noneonly drops the chained traceback from the CLI's exit.Its one blocking finding, that
array.array[float]fails at import on Python 3.12, is wrong: Python 3.12 madearray.arraysubscriptable. The pinned image (3.12.14) evaluates it, and the MCP suite, which imports that module, passes. Security: nothing open.Considered, not done: Dependabot for
requirements-dev.*. The supply-chain slice covers the runtime and MCP locks, and the dev tools never ship.