ruff
AGENTS.md50k starsChanged 2 months agoMITView on GitHub
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). Before starting work on an issue and again before opening a pull request, follow the guidance on avoiding duplicate work. If an open pull request already addresses the issue, do not submit a competing one…
Trending
More talk lately.about the whole repository
Who's talking about astral-sh/ruff
- A Hacker News story“Ruff: Python linter and code formatter written in Rust”Hacker News · Jan 21, 2025 · 200 points
- astral-sh/ty“Reimplement popular Mypy Plugins”GitHub · May 9, 2025 · 55 reactions
- astral-sh/ty“Code completion”GitHub · Mar 14, 2025 · 47 reactions
- astral-sh/ty“Advanced `TypedDict` support”GitHub · Mar 26, 2025 · 43 reactions
- astral-sh/ty“LSP: Support Workspace folders”GitHub · Aug 22, 2024 · 42 reactions
The biggest 5 of 82 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 82
Talked about on Bluesky, GitHub and Hacker News (82 times).
On Bluesky · 50
- Nov 24, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★33024 https://github.com/astral-sh/ruff — @rusttrending.bsky.social10 likes and reposts
- Mar 1, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★36260 https://github.com/astral-sh/ruff — @rusttrending.bsky.social4 likes and reposts
- Mar 26, 2024like the other comments, my ide highlights or adds red squigglies when there's a typing mismatch. the drop-in typing is nice. also +1 for… — @jcsalterego.bsky.social4 likes and reposts · 1 reply
- Jun 6, 2026astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★47839 https://github.com/astral-sh/ruff — @rusttrending.bsky.social3 likes and reposts
- Mar 20, 2026astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★46503 https://github.com/astral-sh/ruff — @rusttrending.bsky.social3 likes and reposts
45 more on Bluesky
- Jan 31, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★35110 https://github.com/astral-sh/ruff — @rusttrending.bsky.social3 likes and reposts
- Jun 11, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★27927 https://github.com/astral-sh/ruff — @rusttrending.bsky.social3 likes and reposts
- Mar 28, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★25477 https://github.com/astral-sh/ruff — @rusttrending.bsky.social3 likes and reposts
- Feb 9, 2024Ruff is great! So what if it's written in Rust? I mean, PyCharm is written in Java, and as long as it's not written in JavaScript, I… — @clairem.secondlife.bio3 likes and reposts · 1 reply
- Aug 8, 2026astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★49106 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Jul 4, 2026astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★48418 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Aug 14, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★41594 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Jul 8, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★40635 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Jan 18, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★34595 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Dec 7, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★33441 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Nov 28, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★33179 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Nov 9, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★32582 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Oct 16, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★31868 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Sep 22, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★31163 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Aug 18, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★29920 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Aug 4, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★29586 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Jul 11, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★28900 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Apr 26, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★26574 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Apr 3, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★25746 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Jan 3, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★21798 https://github.com/astral-sh/ruff — @rusttrending.bsky.social2 likes and reposts
- Nov 6, 2026🔥 Hot Repo! 🔥 (100+ new stars) 📦 astral-sh / ruff ⭐ 50,486 (+107) 🗒 Rust An extremely fast Python linter and code formatter, written in… — @github-trending.bsky.social1 likes and repost
- Nov 6, 2026🔥 Hot Repo! 🔥 (100+ new stars) 📦 astral-sh / ruff ⭐ 50,486 (+107) 🗒 Rust An extremely fast Python linter and code formatter, written in… — @github-trending-rs.bsky.social1 likes and repost
- Sep 23, 2026astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★49734 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Jul 20, 2026astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★48699 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Jan 6, 2026astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★44968 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Dec 20, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★44557 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Oct 25, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★43303 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Oct 2, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★42776 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Sep 6, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★42246 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Jul 22, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★40970 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Jun 17, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★40085 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Jun 1, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★39601 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- May 13, 2025if by "rough" you mean astral's other project github.com/astral-sh/ruff, then no it wouldn't replace that - ruff is a linter/formatter, ty… — @spacegirl.ing1 likes and repost
- May 8, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★38551 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Apr 5, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★37505 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Jan 21, 2025Ruff: Python linter and code formatter written in Rust Discussion — @hackernewsbot.bsky.social1 likes and repost
- Jan 10, 2025astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★34408 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Oct 10, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★31667 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Aug 21, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★30006 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Aug 18, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★29926 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Jun 7, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★27788 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Apr 27, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★26589 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Apr 25, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★26508 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Apr 24, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★26497 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
- Apr 21, 2024astral-sh / ruff: An extremely fast Python linter and code formatter, written in Rust. ★26349 https://github.com/astral-sh/ruff — @rusttrending.bsky.social1 likes and repost
On GitHub · 25
- May 9, 2025Reimplement popular Mypy Plugins — astral-sh/ty55 reactions · 13 comments
- Mar 14, 2025Code completion — astral-sh/ty47 reactions · 11 comments
- Mar 26, 2025Advanced `TypedDict` support — astral-sh/ty43 reactions · 20 comments
- Aug 22, 2024LSP: Support Workspace folders — astral-sh/ty42 reactions · 2 comments
- May 7, 2025Support starred/splatted/unpacked arguments in function calls — astral-sh/ty36 reactions · 15 comments
20 more on GitHub
- Mar 21, 2025Support narrowing on attribute and subscript expressions — astral-sh/ty29 reactions · 17 comments
- Feb 26, 2026Lags after the last update — zed-industries/zed27 reactions · 29 comments
- Apr 28, 2025Advanced dataclass support — astral-sh/ty17 reactions · 15 comments
- Jul 30, 2024Support common python refactoring — zed-industries/zed16 reactions · 2 comments
- Aug 1, 2025Add an experimental `uv format` command — astral-sh/uv14 reactions · 4 comments
- Apr 24, 2026Ruff depth limit — pydantic/monty11 reactions · 3 comments
- Oct 17, 2023Fix: Ruff output option — dense-analysis/ale11 reactions · 11 comments
- Apr 19, 2024refactor: use ruff as the server — sublimelsp/LSP-ruff7 reactions · 9 comments
- Oct 5, 2023Add support for Jupyter Notebook — astral-sh/ruff-lsp6 reactions · 8 comments
- Mar 14, 2025fix: use proper version comparison to support installation of ruff 0.10.x — simhem/asdf-ruff5 reactions · 7 comments
- Jun 2, 2026deps(pip): update ruff requirement from >=0.15.11 to >=0.15.15 — hashgraph-online/hol-guard4 reactions · 2 comments
- Jul 26, 2025Add unified hook for running format and check in a single step — astral-sh/ruff-pre-commit4 reactions · 3 comments
- Feb 29, 2024ruff: 0.2.2 -> 0.3.0 — NixOS/nixpkgs4 reactions · 12 comments
- Jun 11, 2023Implement round-trip fuzzers for finding correctness bugs — rome/tools4 reactions · 20 comments
- Nov 11, 2026chore(deps-dev): bump ruff from 0.17.1 to 0.17.4 — rmems/agoge-forger3 reactions · 6 comments
- Oct 14, 2026chore(deps-dev): bump ruff from 0.16.10 to 0.17.0 — rmems/agoge-forger3 reactions · 5 comments
- Oct 7, 2026chore(deps-dev): bump ruff from 0.16.8 to 0.16.10 — rmems/agoge-forger3 reactions · 5 comments
- Sep 9, 2026chore(deps-dev): bump ruff from 0.16.5 to 0.16.6 — rmems/agoge-forger3 reactions · 5 comments
- Apr 9, 2026chore(deps): update pre-commit hook astral-sh/ruff-pre-commit to v0.16.4 — MH0386/MH0386.github.io3 reactions · 31 comments
- Oct 15, 2025requirements: bump ruff from 0.11.13 to 0.14.0 — buildbot/buildbot0 reactions
On Hacker News · 7
- Jan 21, 2025Ruff: Python linter and code formatter written in Rust200 points · 150 comments
- May 21, 2026Avoid unnecessary parser lookahead for operators3 points
- Dec 3, 2023Ruff: fast Python linter and code formatter, written in Rust3 points
- Sep 25, 2025We adopt an approach I'll call "Thanks I Hate It (TIHI)"2 points
- Nov 27, 2023Ruff: An fast Python linter and code formatter, written in Rust2 points
2 more on Hacker News
- Oct 24, 2023Ruff v0.122 points · 1 comment
- Jan 26, 2024An fast Python linter and code formatter, written in Rust1 point
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository5 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- adding-ty-diagnosticsSkill
- minimizing-ty-ecosystem-changesSkill
- summarise-ecosystem-resultsSkill
- wobbling-ty-constraint-orderSkill
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
31 rules. About 0 are common, 15 are distinctive, and 16 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈15
Distinctive · estimate
This author's own choices. Worth a look.
16
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 7
Before starting work on an issue and again before opening a pull request, follow the guidance on avoiding duplicate work.
- Very specific: line 13
Before opening a PR, inspect the repository's available GitHub labels and the current Rooster configuration, including required and ignored …
- Very specific: line 20
When working on ty, PR titles should start with [ty].
- Distinctive: line 22
If you have permission, apply the selected labels when creating the PR or afterward, then verify that the PR's actual labels include them …
- Distinctive: line 32
When reviewing a branch or pull request, be deliberately nitpicky.
- Distinctive: line 50
Write every mdtest paragraph, code comment, piece of documentation, PR description, and GitHub issue for its eventual reader, not for the …
- Distinctive: line 54
Do not mention discarded alternatives, intermediate edits, private instructions, tool usage, branch or draft status, local test commands, …
- Very specific: line 60
Run all tests (using nextest for faster execution and setting INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 to ensure …
- Distinctive: line 68
Run tests for a specific crate:
- Very specific: line 74
Run a single mdtest file. The path to the mdtest file should be relative to the crates/ty_python_semantic/resources/mdtest folder.
- Very specific: line 88
If cargo nextest is not available, use cargo test with the same environment variables:
- Distinctive: line 106
After running the tests, always review the contents of any snapshots that have been added or updated.
- Very specific: line 108
When running tests with INSTA_FORCE_PASS=1, check for .pending-snap files if any affected tests use inline snapshots.
- Distinctive: line 110
Never edit snapshot files or inline snapshot bodies manually.
- Distinctive: line 120
Prefer examples whose purpose is understandable without following issue links.
- Distinctive: line 121
Prefer direct, present-tense descriptions of behavior over abstract requirements: write "We reject this assignment" rather than "We must …
- Very specific: line 125
When testing generic behavior supported by both legacy and PEP 695 syntax, add equivalent cases under generics/legacy/ and generics/pep695/.
- Very specific: line 135
Use debug builds (not --release) when developing, as release builds lack debug assertions and have slower compile times.
- Distinctive: line 155
When the task matches a more specific ty workflow, also read and follow that skill from the repository root:
- Very specific: line 175
When running ty against a temporary Python reproduction file, create it outside the Ruff checkout (for example, under /tmp).
- Distinctive: line 206
All significant changes must be tested.
- Distinctive: line 207
Look to see if your tests could go in an existing file before adding a new file for your tests.
- Distinctive: line 209
Follow existing code style.
- Very specific: line 210
Prefer narrow visibility by default because this workspace is generally its own consumer.
- Very specific: line 215
Prefer let chains (if let combined with &&) and let guards (PAT if let ...
- Very specific: line 216
If you _have_ to suppress a Clippy lint, prefer to use #[expect()] over [allow()], where possible.
- Very specific: line 218
Run cargo dev generate-all after changing configuration options, CLI arguments, lint rules, or environment variable definitions, as these …
- Very specific: line 219
Don't prefix tests with test_.
- Very specific: line 220
Don't separate struct definitions from their impl blocks unless the impl is deliberately placed in a separate file, as for large structs.
- Distinctive: line 221
Write all self-contained Python scripts as PEP 723 scripts, with inline metadata.
- Very specific: line 222
When running a PEP 723 script, run it with uv run <script>.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Ruff Repository
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).
Before contributing
Before starting work on an issue and again before opening a pull request, follow the guidance on avoiding duplicate work. If an open pull request already addresses the issue, do not submit a competing one without maintainer agreement.
PR conventions
Before opening a PR, inspect the repository's available GitHub labels and the current Rooster
configuration, including required and ignored labels, in the [tool.rooster] and
[tool.rooster.section-labels] sections of Ruff's pyproject.toml and
ty's pyproject.toml. Labels such as
internal, testing, and ci can exclude a PR from a changelog. Decide whether and how the change
should appear in each changelog, then select appropriate labels.
When working on ty, PR titles should start with [ty]. Add the ty GitHub label.
If you have permission, apply the selected labels when creating the PR or afterward, then verify that the PR's actual labels include them and have the intended effect on each changelog. If the available labels or a Rooster configuration could not be inspected, say so when reporting the PR.
Code Review Rules
For security reviews of Ruff and ty runtime changes, use the threat models to assess trust boundaries and calibrate severity.
When reviewing a branch or pull request, be deliberately nitpicky. Report not only bugs and regressions, but also architectural and maintenance risks, weak test coverage, unclear code, unnecessary complexity, and meaningful style or consistency issues. Order findings by severity, cite files and lines, and distinguish blockers from non-blocking improvements. Number each review point for easy reference in subsequent review discussion.
During code review, check the proposed changes against all applicable code, test,
documentation, and architectural conventions in this AGENTS.md. Report
meaningful violations introduced by the changes; do not apply agent-only workflow
instructions to PR authors or flag unrelated pre-existing issues.
For security reviews of repository, CI, and release changes, use the repository threat model to assess trust boundaries and calibrate severity.
Writing for human readers
Write every mdtest paragraph, code comment, piece of documentation, PR description, and GitHub issue for its eventual reader, not for the current Codex conversation. Determine the reader's knowledge, purpose, and likely questions privately; do not add an audience-analysis section to the artifact.
Base public-facing text on the final code, complete final diff, relevant issue, and verified evidence. Explain the observable behavior or problem before implementation details. Use established technical terminology and the actual names of types, functions, files, and invariants.
Do not mention discarded alternatives, intermediate edits, private instructions, tool usage, branch or draft status, local test commands, or session history unless the reader needs that information to understand the final result. Do not describe reverted changes as part of the final change.
Preserve useful human-written comments unless the code change makes them inaccurate. Before finishing, reread each changed artifact as someone with no access to the Codex session and remove or explain anything that would surprise or confuse that reader.
Running Tests
Run all tests (using nextest for faster execution and setting INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 to ensure all snapshots are updated):
INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo nextest runFile-watcher tests do not work inside the sandbox. It is usually unnecessary to run them locally before filing a change unless you are certain that the change affects file-watching behavior.
Run tests for a specific crate:
INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo nextest run -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. Include --test mdtest to avoid building unrelated test binaries:
INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo nextest run -p ty_python_semantic --test mdtest -- 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>" INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo nextest run -p ty_python_semantic --test mdtest -- mdtest::<path/to/mdtest_file.md>Fallback without nextest
If cargo nextest is not available, use cargo test with the same environment variables:
# Run all tests.
INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo test
# Run tests for a specific crate.
INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo test -p ty_python_semantic
# Run a single mdtest file.
INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo test -p ty_python_semantic --test mdtest -- <path/to/mdtest_file.md>
# Run a specific mdtest within a file.
MDTEST_TEST_FILTER="<filter>" INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo test -p ty_python_semantic --test mdtest -- <path/to/mdtest_file.md>Snapshot updates
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.
Never edit snapshot files or inline snapshot bodies manually. Regenerate them by running the relevant tests with the snapshot-update environment variables documented above, then review the generated diff.
Writing mdtests
- Write mdtests as readable, literate specifications, and minimize the context a reader must hold in mind. Prefer short, focused code blocks, and define types, fixtures, and helpers close to the assertions that use them. Sections and subsections can be long when they develop a coherent topic through many short examples interspersed with prose. Do not split a subsection, or flag it in review, solely because of its length. Give independent scenarios separate sibling Markdown test headings at the same level; only introduce child headings if any existing code beneath their parent is first moved into child sections. When scenarios need shared setup, interleave short prose-and-code blocks under the same heading.
- Code blocks for the same file within a section are concatenated into one file. For inline snapshots, keep each example's code block close to its
# snapshotblock. Ideally, any given code block only has one snapshot in it, but one codeblock containing several snapshots is also acceptable. Repeating a short, independent function definition, including one with the same name, is fine if it keeps the code triggering a snapshot close to the snapshot demonstrating the expected diagnostic on that code. Reuse shared setup when clearer, and check that repeated names do not affect other examples. - When a Python statement in an mdtest is included only or primarily to check that ty does not emit a diagnostic for it, normally add a
# no diagnosticcomment on or above the statement. Statements used as setup for later assertions do not necessarily need such comments. - Prioritize document structure and readability over avoiding duplicated setup. Add a test to an existing section when its heading accurately describes the new scenario, adding or improving introductory prose as needed; otherwise, create a separate sibling section, even if that requires repeating a small fixture.
- Order mdtests from basic, common behavior to more specialized cases. Place narrow regression tests alongside closely related examples when they fit naturally; otherwise, put them near the end of the relevant section or file. Do not put an obscure special case at the beginning simply because it is the newest regression.
- Aim for readable documents that serve as both documentation and tests. Use prose to explain the key type checker behavior and its rationale where helpful. A sentence or fragment may suffice; avoid repeating what the heading, surrounding explanation, or assertions already make clear. Use clear, precise terminology. Avoid using jargon where it's unnecessary, and avoid inventing new jargon if there's an existing term of art used in that file. Avoid long paragraphs covering multiple scenarios followed by a single long code block.
- Prefer examples whose purpose is understandable without following issue links. For narrow regressions, a brief issue reference can be enough when additional explanation would merely restate the code or obscure the relevant behavior.
- Prefer direct, present-tense descriptions of behavior over abstract requirements: write "We reject this assignment" rather than "We must reject this assignment."
- Keep each code example as simple as possible while still demonstrating the key behavior. When adapting real-world code or an issue reproducer, remove incidental types, methods, type parameters, imports, and domain-specific details. Preserve complexity only when necessary to reproduce the regression or distinguish the intended behavior, and reuse nearby fixtures or simple built-in types when doing so keeps the test easy to understand.
- Prefer a minimal, purpose-built custom type over a standard-library type when a regression depends on particular attributes, methods, bounds, or constraints. Define the relevant behavior in the test so readers do not need to look up the standard-library type to understand the scenario. For commonly used standard-library types, consider adding a separate regression using the real type to protect against changes in typeshed.
- Place each mdtest in a file for the behavior it actually tests, and assert that behavior directly. Prefer an existing file when one already covers that behavior; create a new file when no existing file is a good fit. Do not choose a file solely because its directive or helper can express the assertion.
- When testing generic behavior supported by both legacy and PEP 695 syntax, add equivalent cases under
generics/legacy/andgenerics/pep695/.
Running Clippy
CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-featuresRunning Debug Builds
Use 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.pyWorking on ty
The guidance in this section applies to edits to ty* crates, reviews of ty PRs, or other work when the ty type checker has been specifically mentioned by the user.
Related skills
When the task matches a more specific ty workflow, also read and follow that skill from the repository root:
- Adding new ty rules, changing diagnostics or diagnostic messages, or reviewing diagnostics:
.agents/skills/adding-ty-diagnostics/SKILL.md. - Ecosystem report summaries:
.agents/skills/summarise-ecosystem-results/SKILL.md. - Reproducing, investigating, or minimizing ecosystem or primer differences:
.agents/skills/minimizing-ty-ecosystem-changes/SKILL.md.
Completion ranking
When changing ty autocomplete ranking, add or update evaluation fixtures under crates/ty_completion_eval/truth/. Extend an existing project when it is a good fit for the behavior being tested; otherwise, add a new one. Use <CURSOR:expected_name> directives to assert ranking, and include the expected module for auto-import completions. Add completion.rs unit tests only when the evaluation fixtures cannot adequately cover the behavior.
Regenerate and review the committed evaluation results after changing ranking behavior or fixtures:
CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_LTO=off CARGO_PROFILE_DEV_DEBUG="line-tables-only" cargo run --package ty_completion_eval -- all --threshold 0.4 --tasks crates/ty_completion_eval/completion-evaluation-tasks.csvTo inspect one evaluation task, run cargo run --package ty_completion_eval -- show-one <fixture-name> --file-name <file-name> --index <cursor-index>.
Ad hoc reproductions
When running ty against a temporary Python reproduction file, create it outside the Ruff checkout (for example, under /tmp). A file inside the checkout discovers Ruff's root pyproject.toml, whose requires-python = ">=3.7" causes ty to infer Python 3.7 as the default Python version.
The db parameter
For free functions and associated functions without a self parameter, db should be the first parameter. For methods with a self parameter, db should come immediately after self.
Salsa tips
Tracked functions and methods
Adding #[salsa::tracked] to a function or method means that the Salsa framework will cache the function/method.
This can sometimes be done for performance reasons, and can also be done to ensure incremental computation in an
IDE context.
Methods that access .node() should usually be #[salsa::tracked], or ty's incrementality will suffer:
we don't want to accidentally introduce a dependency on module a's AST in a Salsa query that would be
called when type-checking module b. Prefer higher-level semantic APIs over raw AST access where possible,
but ask for guidance from the user if this would require significant refactoring.
Reduce memory usage where possible
For Salsa-cached values, avoid retaining excess collection capacity. Prefer boxed slices; otherwise shrink collections that may have spare capacity before returning them. In particular, inspect HashMap and HashSet values constructed via extend, collect, explicit reservation, or removal, since those operations can leave capacity that insert-only construction does not.
Salsa caching can occur due to a function/method having #[salsa::tracked] on it, or due to a struct with #[salsa::interned] being constructed.
Generated Release Workflow
Parts of .github/workflows/release.yml are generated by cargo-dist from dist-workspace.toml. Before editing the release workflow, check whether the relevant section is generated. Prefer changing dist-workspace.toml or the referenced reusable workflow instead of editing generated YAML. After modifying cargo-dist configuration, regenerate the workflow with the cargo-dist version pinned in dist-workspace.toml and inspect the resulting diff to ensure the change will survive future regenerations.
Development Guidelines
- All significant changes must be tested. Add or update focused tests for semantic changes when existing coverage does not already establish the intended behavior.
- 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
uv run --only-dev --locked prekat the end of a task if you changed files in the repo. This includes changes such as rebases or addressing review comments. Useuv run --only-dev --locked 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. Useuv run --only-dev --locked prek run --all-fileswhen a full-repository hook sweep is specifically needed. - Before writing significant amounts of new code, look for existing utilities or mechanisms that could solve the problem. Avoid expanding the task to unrelated issues, but do not confuse keeping the task focused with minimizing the size of the implementation. Prefer addressing the underlying architectural problem over adding a localized workaround, even when doing so requires a substantial refactor or rearchitecture. Ask the user for guidance if in doubt about whether to attempt a larger refactor or not.
- Try hard to avoid patterns that require
panic!,unreachable!,.unwrap()or.expect(). 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&&) and let guards (PAT if let ... =>) 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 orletguards. - 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. - Don't use comments to narrate code, but do use them to explain invariants and why something unusual was done a particular way. Make sure that a comment will make sense to somebody who's reading the code for the first time. Prefer plain language, avoid jargon, and don't be afraid to be more verbose if it's necessary to explain something well. Giving examples of the kind of Python code we're trying to model at this particular point in Ruff or ty can often be very helpful for future readers of the code.
- 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. - Write all self-contained Python scripts as PEP 723 scripts, with inline metadata.
- When running a PEP 723 script, run it with
uv run <script>. If a script doesn't have PEP 723 metadata, run it with--no-project,--script, or similar to avoid building Ruff from source, which is very slow and usually unnecessary.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

