feat: add Python type checking via embedded ty - #194
Draft
sd2k wants to merge 8 commits into
Draft
Conversation
New workspace crate that embeds ruff's Python parser and ty's type checker as git dependencies (pinned to the ruff commit used by ty 0.0.29). Exposes two APIs: - check_syntax(): fast syntax validation via ruff_python_parser - check_types(): full type checking via ty with typeshed stubs Uses a minimal salsa database with an in-memory filesystem to run ty without touching disk. Kept as a separate crate to avoid bloating eryx-server with the ty/salsa dependency tree. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…pporting files Adds a unary Check RPC to the gRPC server for static analysis of Python code before execution. Uses ty (Astral's type checker) embedded as a Rust library dependency via git pin. eryx-check crate additions: - stubs.rs: generates .pyi stub files from CallbackDeclarations so the type checker can validate `await query_loki(expr=...)` calls - check_types_with_options(): accepts supporting files and callback declarations, writes them to an in-memory filesystem, and runs ty - Offset adjustment for diagnostics when callback import is prepended eryx-server additions: - Check RPC in proto: CheckRequest (code, files, callbacks) → CheckResponse (diagnostics with severity, source, byte offsets) - Service handler runs type checking on a blocking thread via spawn_blocking since it's CPU-bound - Reuses existing SupportingFile and CallbackDeclaration proto messages Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The ruff/ty crates use edition 2024 which requires Rust 1.92+. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Updates all references to match the MSRV bump in Cargo.toml. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
🌐 Demo preview: https://feat-eryx-check.eryx-bvy.pages.dev |
Workspace lints warn on unwrap_used; allow it in test modules to match the pattern used by other crates (e.g. grpc_e2e.rs). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
9 tests covering: valid code, syntax errors, type errors, supporting module files, DATA file filtering, callback stubs (correct usage, wrong arg type, optional params), and diagnostic offset validation. Also fixes the Check handler to run both check_syntax() and check_types_with_options() so syntax errors are always reported even if the type checker setup fails. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Eryx scripts use PyCF_ALLOW_TOP_LEVEL_AWAIT at runtime, so top-level `await`, `async for`, and `async with` are valid. Suppress the corresponding ty diagnostics since they're false positives for eryx. Adds an e2e test for top-level await with callback stubs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds ruff's Python formatter as a library dependency and exposes it via a new unary Format RPC. The formatter operates on raw user source code directly — no preamble or stubs needed since formatting is purely syntactic. - eryx-check: adds format_source() wrapping ruff_python_formatter - Proto: FormatRequest (code) → FormatResponse (formatted_code, error) - Server: spawn_blocking handler, returns error for syntax-invalid code - 4 e2e tests: whitespace fixes, idempotent, syntax error, multiline Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
eryx-checkcrate that embeds ruff's Python parser and ty's type checker as Rust library dependencies (git-pinned to the ruff commit used by ty 0.0.29)CheckgRPC RPC toeryx-serverfor static analysis of Python code before execution.pyicallback stubs fromCallbackDeclarations soawait query_loki(expr=...)is type-checked against the declared parameter typeseryx-check crate
check_syntax()— fast syntax validation via ruff's parsercheck_types()— full type checking via ty with typeshed stubscheck_types_with_options()— accepts supporting files and callback declarationsCheck RPC
rpc Check(CheckRequest) returns (CheckResponse)— unary, no streaming neededSupportingFileandCallbackDeclarationproto messagesspawn_blockingsince type checking is CPU-boundDependencies
eryx-checkcrate — no impact oneryx-serverbinary size unless opted intoTest plan
eryx-check(stub generation, syntax checking, type checking, callback validation, offset adjustment)eryx-serverpass (pre-existing)cargo clippy -p eryx-check -p eryx-server -- -D warningsclean🤖 Generated with Claude Code