Commit graph

12312 commits

Author SHA1 Message Date
Brent Westbrook
519b6fa850 file_level -> hide_snippet 2025-09-26 18:03:21 -04:00
Brent Westbrook
0668704fcc add a todo about the offset hack 2025-09-26 18:02:06 -04:00
Brent Westbrook
aee8fd3659 DiagnosticId::FormatError -> InternalError 2025-09-26 18:00:05 -04:00
Brent Westbrook
73eb86d0f5 DiagnosticId::RangeFormatNotebook -> InvalidCliOption 2025-09-26 18:00:02 -04:00
Brent Westbrook
c1a3b44a05 reuse FormatCommandError::Write instead of Diff
the diff variant was only used for reporting a failure writing the diff to
stdout
2025-09-26 17:56:59 -04:00
Brent Westbrook
ed63b7e495 calculate a real range for the diagnostics
note that several of the tests in format.rs still start at 1:1. This is because
the newlines in the `say_hy` examples with raw strings are actually part of the
code passed to the formatter, which removes these initial newlines.
2025-09-26 16:35:46 -04:00
Brent Westbrook
05faf43ca6 add DisplayParseError::error and render the ParseErrorType directly 2025-09-26 16:20:51 -04:00
Brent Westbrook
723d1d56ea use FormatError for PrintError 2025-09-26 15:39:14 -04:00
Brent Westbrook
090468d961 delete TODO for ignore::Errors 2025-09-26 15:23:32 -04:00
Brent Westbrook
28ebcd555e factor out create_panic_diagnostic, reuse in the linter
I also added the <location> filter I was using in the formatter to the linter
tests. This isn't strictly necessary but will be a bit more convenient if the
source of the panic ever shifts around in the future.
2025-09-26 15:14:25 -04:00
Brent Westbrook
78fdc60d5c sort errors and diagnostics together 2025-09-26 15:14:07 -04:00
Brent Westbrook
451dc0c432 emit a warning for non-preview --output-format usage
as a global option, preview comes from the resolved settings, so I just moved
the pyproject.toml resolution outside of `format` and `format_stdin` since it
was called immediately in both cases anyway.

note that this won't warn for usage of the `output-format` setting within a
pyproject.toml because that option will already have been `unwrap_or_default`ed
by the time we could check it here.
2025-09-26 15:10:23 -04:00
Brent Westbrook
007a22f1c0 point out preview restriction on format --output-format 2025-09-26 15:10:21 -04:00
Brent Westbrook
2ce8f80877 use FormatResult::diff for checking, revert other changes
to FormatResult and to FormattedSource
2025-09-26 14:00:00 -04:00
Brent Westbrook
959f55ae05 add error tests, set_file_level, and improve panic formatting 2025-09-25 17:16:39 -04:00
Brent Westbrook
a43fa93249 factor out PanicError::to_diagnostic_message 2025-09-25 17:06:53 -04:00
Brent Westbrook
39f96cc9f0 allow passing a header offset into annotate-snippets
as shown in the snapshot changes, this allows us to manually align what
annotate-snippets calls the header sigil (the `-->` arrow in the diagnostic
header) with our diff line number separators.

these were aligned automatically in the linter because we were also emitting
snippets with annotate-snippets with the same line numbers, but since the
formatter diagnostics only have diffs and not snippets, the default line number
width was zero.

note that this still isn't perfect because we align with the highest line number
in the entire file, not necessarily the highest _rendered_ line number, as shown
in the updated notebook snapshot. still, it should get us closer to aligned than
not having an offset at all and also end up being correct in most(?) cases.
2025-09-25 16:55:21 -04:00
Brent Westbrook
4ea16b7dd6 convert errors to diagnostics too 2025-09-25 16:43:53 -04:00
Brent Westbrook
a5ec195c53 build a real notebook index and render cell diffs 2025-09-25 16:35:25 -04:00
Brent Westbrook
7e48156af0 convert FormatPathResults to Diagnostics just before rendering 2025-09-25 16:25:38 -04:00
Brent Westbrook
76e63b36bd add CellOffsets::ranges helper 2025-09-25 16:15:33 -04:00
Brent Westbrook
5bfe3f2440 fix a couple of Rome references 2025-09-25 16:06:42 -04:00
Brent Westbrook
9cffdd808e suppress the URL for all non-lint DiagnosticIds
instead of just syntax errors
2025-09-25 15:56:10 -04:00
Brent Westbrook
9bb4374fd7 respect show_fix_status for full output
this wasn't a problem for the linter because we always want to show the fix
status, but we don't need the visual clutter of marking every formatter
diagnostic as fixable
2025-09-25 15:46:21 -04:00
Brent Westbrook
041b35dafc allow tempdir_filter to take any AsRef<Path>
this is convenient for passing in the result of tempdir.join calls and matches
the version in lint.rs
2025-09-25 15:38:03 -04:00
Brent Westbrook
92208abd55 add --output-format to the ruff format cli 2025-09-25 15:29:41 -04:00
Brent Westbrook
4620604a20 add DiagnosticId::Unformatted 2025-09-25 15:17:20 -04:00
Bhuminjay Soni
cfc64d1707
[syntax-errors]: future-feature-not-defined (F407) (#20554)
<!--
Thank you for contributing to Ruff/ty! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title? (Please prefix
with `[ty]` for ty pull
  requests.)
- Does this pull request include references to any relevant issues?
-->

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->

This PR implements
https://docs.astral.sh/ruff/rules/future-feature-not-defined/ (F407) as
a semantic syntax error.

## Test Plan

<!-- How was it tested? -->

I have written inline tests as directed in #17412

---------

Signed-off-by: 11happy <soni5happy@gmail.com>
2025-09-25 13:52:24 -04:00
Brent Westbrook
6b7a9dc2f2
[isort] Clarify dependency between order-by-type and case-sensitive settings (#20559)
Summary
--

Fixes #20536 by linking between the isort options `case-sensitive` and
`order-by-type`. The latter takes precedence over the former, so it
seems good to clarify this somewhere.

I tweaked the wording slightly, but this is otherwise based on the patch
from @SkylerWittman in
https://github.com/astral-sh/ruff/issues/20536#issuecomment-3326097324
(thank you!)

Test Plan
--

N/a

---------

Co-authored-by: Skyler Wittman <skyler.wittman@gmail.com>
Co-authored-by: Micha Reiser <micha@reiser.io>
2025-09-25 16:25:12 +00:00
Brent Westbrook
9903104328
[pylint] Fix missing max-nested-blocks in settings display (#20574)
Summary
--

This fixes a bug pointed out in #20560 where one of the `pylint`
settings wasn't used in its `Display` implementation.

Test Plan
--

Existing tests with updated snapshots
2025-09-25 12:14:28 -04:00
Giovani Moutinho
beec2f2dbb
[flake8-simplify] Improve help message clarity (SIM105) (#20548)
## Summary

Improve the SIM105 rule message to prevent user confusion about how to
properly use `contextlib.suppress`.

The previous message "Replace with `contextlib.suppress(ValueError)`"
was ambiguous and led users to incorrectly use
`contextlib.suppress(ValueError)` as a statement inside except blocks
instead of replacing the entire try-except-pass block with `with
contextlib.suppress(ValueError):`.

This change makes the message more explicit:
- **Before**: `"Use \`contextlib.suppress({exception})\` instead of
\`try\`-\`except\`-\`pass\`"`
- **After**: `"Replace \`try\`-\`except\`-\`pass\` block with \`with
contextlib.suppress({exception})\`"`

The fix title is also updated to be more specific:
- **Before**: `"Replace with \`contextlib.suppress({exception})\`"`  
- **After**: `"Replace \`try\`-\`except\`-\`pass\` with \`with
contextlib.suppress({exception})\`"`

Fixes #20462

## Test Plan

-  All existing SIM105 tests pass with updated snapshots
-  Cargo clippy passes without warnings  
-  Full test suite passes
-  The new messages clearly indicate that the entire try-except-pass
block should be replaced with a `with` statement, preventing the misuse
described in the issue

---------

Co-authored-by: Giovani Moutinho <e@mgiovani.dev>
2025-09-25 11:19:26 -04:00
Micha Reiser
c256c7943c
[ty] Update salsa to fix hang when cycle head panics (#20577) 2025-09-25 17:13:07 +02:00
Dhruv Manilawala
35ed55ec8c
[ty] Filter overloads using variadic parameters (#20547)
## Summary

Closes: https://github.com/astral-sh/ty/issues/551

This PR adds support for step 4 of the overload call evaluation
algorithm which states that:

> If the argument list is compatible with two or more overloads,
determine whether one or more of the overloads has a variadic parameter
(either `*args` or `**kwargs`) that maps to a corresponding argument
that supplies an indeterminate number of positional or keyword
arguments. If so, eliminate overloads that do not have a variadic
parameter.

And, with that, the overload call evaluation algorithm has been
implemented completely end to end as stated in the typing spec.

## Test Plan

Expand the overload call test suite.
2025-09-25 14:58:00 +00:00
Brent Westbrook
b0bdf0334e
Bump 0.13.2 (#20576) 2025-09-25 10:37:46 -04:00
Brent Westbrook
7331d393c5
Update rooster to 0.1.0 (#20575)
Summary
--

This reduces the page size of GraphQL queries
(https://github.com/zanieb/rooster/pull/85), hopefully helping with some
of the 502s we've been hitting.

Test Plan
--

I ran the release script, and it succeeded after failing several times
on the old rooster version.
2025-09-25 10:11:21 -04:00
David Peter
529e5fa6c2
[ty] Ecosystem analyzer: timing report (#20571)
## Summary

Generate a timing diff across the whole ecosystem and deploy it to
CloudFlare pages. The timing information is collected already, we just
need to create and upload the HTML report.

The timing results are just based on a single run. No statistical
analysis across multiple runs or similar is performed. This means that
results can be noisy, as can be seen on this PR, where we see slowdowns
up to 1.26× and speedups down to 0.89×, even though the change should be
neutral. Across all projects, these random events cancel out and we see
an average factor of 1.01×. So I think this feature can still be
interesting, given that it comes "for free". We just need to keep in
mind that it will be noisy, and shouldn't read too much into these
results.

## Test Plan

CI run on this PR (see the new *timing results* link).
2025-09-25 14:14:20 +02:00
David Peter
efbb80f747
[ty] Remove hack in protocol satisfiability check (#20568)
## Summary

This removes a hack in the protocol satisfiability check that was
previously needed to work around missing assignability-modeling of
inferable type variables. Assignability of type variables is not
implemented fully, but some recent changes allow us to remove that hack
with limited impact on the ecosystem (and the test suite). The change in
the typing conformance test is favorable.

## Test Plan

* Adapted Markdown tests
* Made sure that this change works in combination with
https://github.com/astral-sh/ruff/pull/20517
2025-09-25 13:35:47 +02:00
Micha Reiser
9f3cffc65c
Add 'Finding ways to help' to CONTRIBUTING.md (#20567)
Some checks are pending
CI / cargo clippy (push) Blocked by required conditions
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / benchmarks instrumented (ruff) (push) Blocked by required conditions
CI / benchmarks instrumented (ty) (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
CI / check playground (push) Blocked by required conditions
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2025-09-25 12:46:41 +02:00
Alex Waygood
21be94ac33
[ty] Explicitly test assignability/subtyping between unions of nominal types and protocols with method members (#20557) 2025-09-25 09:21:29 +00:00
Alex Waygood
b7d5dc98c1
[ty] Add tests for interactions of @classmethod, @staticmethod, and protocol method members (#20555) 2025-09-25 10:14:53 +01:00
Dhruv Manilawala
e1bb74b25a
[ty] Match variadic argument to variadic parameter (#20511)
## Summary

Closes: https://github.com/astral-sh/ty/issues/1236

This PR fixes a bug where the variadic argument wouldn't match against
the variadic parameter in certain scenarios.

This was happening because I didn't realize that the `all_elements`
iterator wouldn't keep on returning the variable element (which is
correct, I just didn't realize it back then).

I don't think we can use the `resize` method here because we don't know
how many parameters this variadic argument is matching against as this
is where the actual parameter matching occurs.

## Test Plan

Expand test cases to consider a few more combinations of arguments and
parameters which are variadic.
2025-09-25 07:51:56 +00:00
Aria Desires
edeb45804e
[ty] fallback to resolve_real_module in file_to_module (#20461)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / fuzz parser (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks instrumented (ruff) (push) Blocked by required conditions
CI / benchmarks instrumented (ty) (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
This is a naive(?) implementation of the approach @MichaReiser
originally suggested to me in https://github.com/astral-sh/ty/issues/869

Fixes https://github.com/astral-sh/ty/issues/869
Fixes https://github.com/astral-sh/ty/issues/1195
2025-09-24 21:15:35 -04:00
Ibraheem Ahmed
bea92c8229
[ty] More precise type inference for dictionary literals (#20523)
## Summary

Extends https://github.com/astral-sh/ruff/pull/20360 to dictionary
literals. This also improves our `TypeDict` support by passing through
nested type context.
2025-09-24 18:12:00 -04:00
Ed Cuss
f2cc2f604f
[flake8-pyi] Avoid syntax error from conflict with PIE790 (PYI021) (#20010)
<!--
Thank you for contributing to Ruff/ty! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title? (Please prefix
with `[ty]` for ty pull
  requests.)
- Does this pull request include references to any relevant issues?
-->

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->
First contribution so please let me know if I've made a mistake
anywhere. This was aimed to fix #19982, it adds the isolation level to
PYI021 to in the same style as the PIE790 rule.

fixes: #19982

## Test Plan

<!-- How was it tested? -->
I added a case to the PYI021.pyi file where the two rules are present as
there wasn't a case with them both interacting, using the minimal
reproducible example that @ntBre created on the issue (I think I got the
`# ERROR` markings wrong, so please let me know how to fix that if I
did).

---------

Co-authored-by: Brent Westbrook <brentrwestbrook@gmail.com>
2025-09-24 21:26:59 +00:00
Dan Parizher
c361e2f759
[flake8-bandit] Clarify the supported hashing functions (S324) (#20534)
## Summary

Fixes #16572

---------

Co-authored-by: Brent Westbrook <brentrwestbrook@gmail.com>
2025-09-24 20:10:23 +00:00
Alex Waygood
0e83af0b80
Bump mypy_primer pin (#20558) 2025-09-24 19:45:47 +00:00
Bhuminjay Soni
e6073d0cca
[syntax-errors]: multiple-starred-expressions (F622) (#20243)
<!--
Thank you for contributing to Ruff/ty! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title? (Please prefix
with `[ty]` for ty pull
  requests.)
- Does this pull request include references to any relevant issues?
-->

## Summary

This PR implements
https://docs.astral.sh/ruff/rules/multiple-starred-expressions/ as a
semantic syntax error

## Test Plan

 I have added inline tests as directed in #17412

---------

Signed-off-by: 11happy <soni5happy@gmail.com>
Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
2025-09-24 19:32:55 +00:00
Brent Westbrook
73b4b1ed17
[ty] Make FileResolver::path return a full path (#20550)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / benchmarks instrumented (ruff) (push) Blocked by required conditions
CI / benchmarks instrumented (ty) (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
## Summary

Fixes https://github.com/astral-sh/ty/issues/1242

From finding references with the LSP, `FileResolver::path` is only
called once, in `UnifiedFile::path`, so I went through those references,
and it looked safe to make this change in every case. Most of the
references are in the various output formats, where we inherited the
absolute vs relative path decision from Ruff. Two other uses are as
fallbacks if converting a relativized path to a string fails. Finally,
we use the path for sorting and in `UnifiedFile::relative_path`.

## Test Plan

Existing tests, with snapshots updated to show absolute paths (in the
`TestDb` this just added a `/` in front of the file names). I also
updated the GitLab CLI test to set the `CI_PROJECT_DIR` environment
variable and ran a test in GitLab CI:

<img width="613" height="114" alt="image"
src="https://github.com/user-attachments/assets/8ab81dba-54fd-4a24-9110-77ef89293cff"
/>
2025-09-24 13:16:51 -04:00
Amethyst Reese
83f80effec
include .pyw files by default when linting and formatting (#20458)
- Adds test cases exercising file selection by extension with
`--preview` enabled and disabled.
- Adds `INCLUDE_PREVIEW` with file patterns including `*.pyw`.
- In global preview mode, default configuration selects patterns from
`INCLUDE_PREVIEW`.
- Manually tested ruff server with local vscode for both formatting and
linting of a `.pyw` file.

Closes https://github.com/astral-sh/ruff/issues/13246
2025-09-24 08:39:30 -07:00
David Peter
fcc76bb7b2
[ty] Todo-types for os.fdopen, NamedTemporaryFile, and Path.open (#20549)
## Summary

This applies the trick that we use for `builtins.open` to similar
functions that have the same problem. The reason is that the problem
would otherwise become even more pronounced once we add understanding of
the implicit type of `self` parameters, because then something like
`(base_path / "test.bin").open("rb")` also leads to a wrong return type
and can result in false positives.

## Test Plan

New Markdown tests
2025-09-24 15:43:58 +02:00