This repository contains both Ruff (a Python linter and formatter) and ty (a Python type checker). The crates follow a naming convention: ruff_* for Ruff-specific code and ty_* for ty-specific code. ty reuses several Ruff crates, including the Python parser (ruff_python_parser) and AST definitions (ruff_python_ast).
Run all tests (setting CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_DEBUG="line-tables-only" to enable optimizations while retaining some debug info, and setting INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 to ensure all snapshots are updated):
CARGO_PROFILE_DEV_OPT_LEVEL=1 INSTA_FORCE_PASS=1 INSTA_UPDATE=always CARGO_PROFILE_DEV_DEBUG="line-tables-only" MDTEST_UPDATE_SNAPSHOTS=1 cargo testRun tests for a specific crate:
CARGO_PROFILE_DEV_OPT_LEVEL=1 INSTA_FORCE_PASS=1 INSTA_UPDATE=always CARGO_PROFILE_DEV_DEBUG="line-tables-only" MDTEST_UPDATE_SNAPSHOTS=1 cargo test -p ty_python_semanticRun a single mdtest file. The path to the mdtest file should be relative to the crates/ty_python_semantic/resources/mdtest folder:
CARGO_PROFILE_DEV_OPT_LEVEL=1 INSTA_FORCE_PASS=1 INSTA_UPDATE=always CARGO_PROFILE_DEV_DEBUG="line-tables-only" MDTEST_UPDATE_SNAPSHOTS=1 cargo test -p ty_python_semantic --test mdtest -- <path/to/mdtest_file.md>To run a specific mdtest within a file, use a substring of the Markdown header text as MDTEST_TEST_FILTER. Only use this if it's necessary to isolate a single test case:
MDTEST_TEST_FILTER="<filter>" CARGO_PROFILE_DEV_OPT_LEVEL=1 INSTA_FORCE_PASS=1 INSTA_UPDATE=always CARGO_PROFILE_DEV_DEBUG="line-tables-only" MDTEST_UPDATE_SNAPSHOTS=1 cargo test -p ty_python_semantic --test mdtest -- <path/to/mdtest_file.md>After running the tests, always review the contents of any snapshots that have been added or updated.
When running tests with INSTA_FORCE_PASS=1, check for .pending-snap files if any affected tests use inline snapshots.
cargo clippy --workspace --all-targets --all-features -- -D warningsUse debug builds (not --release) when developing, as release builds lack debug assertions and have slower compile times.
Run Ruff:
cargo run --bin ruff -- check path/to/file.pyRun ty:
cargo run --bin ty -- check path/to/file.pyWhen working on ty, first read .agents/skills/working-on-ty/SKILL.md, then also read and follow any more specific ty skills it points to.
- All changes must be tested. If you're not testing your changes, you're not done.
- Look to see if your tests could go in an existing file before adding a new file for your tests.
- Get your tests to pass. If you didn't run the tests, your code does not work.
- Follow existing code style. Check neighboring files for patterns.
- Prefer narrow visibility by default because this workspace is generally its own consumer. However, do not add workarounds solely to avoid
pub: make an item public when another workspace crate needs it and that produces the cleaner implementation. - Rust imports should always go at the top of the file, never locally in functions.
- Run
uvx prekat the end of a task if you changed files in the repo. This includes changes such as rebases or addressing review comments. Useuvx prek run --files <path1> <path2>and pass every file you changed. This keeps the hook run independent of staged state and avoids sweeping unrelated changes. Useuvx prek run -awhen a full-repository hook sweep is specifically needed. - Avoid writing significant amounts of new code. This is often a sign that we're missing an existing method or mechanism that could help solve the problem. Look for existing utilities first.
- Try hard to avoid patterns that require
panic!,unreachable!, or.unwrap(). Instead, try to encode those constraints in the type system. Don't be afraid to write code that's more verbose or requires largeish refactors if it enables you to avoid these unsafe calls. - Prefer let chains (
if letcombined with&&) over nestedif letstatements to reduce indentation and improve readability. At the end of a task, always check your work to see if you missed opportunities to useletchains. - If you have to suppress a Clippy lint, prefer to use
#[expect()]over[allow()], where possible. But if a lint is complaining about unused/dead code, it's usually best to just delete the unused code. - Use comments purposefully. Don't use comments to narrate code, but do use them to explain invariants and why something unusual was done a particular way.
- Run
cargo dev generate-allafter changing configuration options, CLI arguments, lint rules, or environment variable definitions, as these changes require regeneration of schemas, docs, and CLI references. - Don't prefix tests with
test_. - Don't separate struct definitions from their
implblocks unless theimplis deliberately placed in a separate file, as for large structs. - Avoid running
uv runfor any scripts from the repository root unless you use--no-project,--scriptor similar. Usinguv runfrom the Ruff repo root without these flags will build Ruff from source, which is very slow and usually unnecessary.