-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Move concise diagnostic rendering to ruff_db
#19398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
I think this is ready for a first review. The preview changes in the ecosystem are expected, but maybe undesirable. A couple of them look useful, but I'm definitely open to suppressing this for now if we want to try to make some of the fix suggestions less redundant with the main message before exposing them to users in this format. |
ruff_dbruff_db
|
I'll take a closer look tomorrow and try to come up with a suggestion. I don't think we can keep the rendering as is. The messages contain too much redundant information now |
|
Isn't your other PR addressing the difference in rendering (by moving the help text?) |
Oh yeah, I think you're right. I was only thinking about the |
|
I'll review this after rebasing ontop of your ohter PR. That will make it easier for me to understand the scope of the changes. |
to create_notebook_diagnostics docs
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
unresolved-import |
134 | 134 | 0 |
invalid-argument-type |
5 | 5 | 0 |
invalid-assignment |
4 | 4 | 0 |
possibly-unresolved-reference |
4 | 4 | 0 |
possibly-unbound-attribute |
1 | 1 | 0 |
unresolved-reference |
1 | 1 | 0 |
| Total | 149 | 149 | 0 |
* main: [ty] Fix narrowing and reachability of class patterns with arguments (#19512) [ty] Implemented partial support for "find references" language server feature. (#19475) [`flake8-use-pathlib`] Add autofix for `PTH101`, `PTH104`, `PTH105`, `PTH121` (#19404) [`perflint`] Parenthesize generator expressions (`PERF401`) (#19325) [`pep8-naming`] Fix `N802` false positives for `CGIHTTPRequestHandler` and `SimpleHTTPRequestHandler` (#19432) [`pylint`] Handle empty comments after line continuation (`PLR2044`) (#19405) Move concise diagnostic rendering to `ruff_db` (#19398) [ty] highlight the argument in `static_assert` error messages (#19426) [ty] Infer single-valuedness for enums based on `int`/`str` (#19510) [ty] Restructure submodule query around `File` dependency [ty] Make `Module` a Salsa ingredient [ty] Reachability analysis for `isinstance(…)` branches (#19503) [ty] Normalize single-member enums to their instance type (#19502) [ty] Invert `ty_ide` and `ty_project` dependency (#19501) [ty] Implement mock language server for testing (#19391) [ty] Detect enums if metaclass is a subtype of EnumType/EnumMeta (#19481) [ty] perform type narrowing for places marked `global` too (#19381)
## Summary
This PR moves most of the work of rendering concise diagnostics in Ruff
into `ruff_db`, where the code is shared with ty. To accomplish this
without breaking backwards compatibility in Ruff, there are two main
changes on the `ruff_db`/ty side:
- Added the logic from Ruff for remapping notebook line numbers to cells
- Reordered the fields in the diagnostic to match Ruff and rustc
```text
# old
error[invalid-assignment] try.py:3:1: Object of type `Literal[1]` is not
assignable to `str`
# new
try.py:3:1: error[invalid-assignment]: Object of type `Literal[1]` is
not assignable to `str`
```
I don't think the notebook change failed any tests on its own, and only
a handful of snaphots changed in ty after reordering the fields, but
this will obviously affect any other uses of the concise format, outside
of tests, too.
The other big change should only affect Ruff:
- Added three new `DisplayDiagnosticConfig` options
Micha and I hoped that we could get by with one option
(`hide_severity`), but Ruff also toggles `show_fix_status` itself,
independently (there are cases where we want neither severity nor the
fix status), and during the implementation I realized we also needed
access to an `Applicability`. The main goal here is to suppress the
severity (`error` above) because ruff only uses the `error` severity and
to use the secondary/noqa code instead of the line name
(`invalid-assignment` above).
```text
# ty - same as "new" above
try.py:3:1: error[invalid-assignment]: Object of type `Literal[1]` is
not assignable to `str`
# ruff
try.py:3:1: RUF123 [*] Object of type `Literal[1]` is not assignable to
`str`
```
This part of the concise diagnostic is actually shared with the `full`
output format in Ruff, but with the settings above, there are no
snapshot changes to either format.
## Test Plan
Existing tests with the handful of updates mentioned above, as well as
some new tests in the `concise` module.
Also this PR. Swapping the fields might have broken mypy_primer, unless
it occasionally times out on its own.
I also ran this script in the root of my Ruff checkout, which also has
CPython in it:
```shell
flags=(--isolated --no-cache --no-respect-gitignore --output-format concise .)
diff <(target/release/ruff check ${flags[@]} 2> /dev/null) \
<(ruff check ${flags[@]} 2> /dev/null)
```
This yielded an expected diff due to some t-string error changes on main
since 0.12.4:
```diff
33622c33622
< crates/ruff_python_parser/resources/inline/err/f_string_lambda_without_parentheses.py:1:15: SyntaxError: Expected an element of or the end of the f-string
---
> crates/ruff_python_parser/resources/inline/err/f_string_lambda_without_parentheses.py:1:15: SyntaxError: Expected an f-string or t-string element or the end of the f-string or t-string
33742c33742
< crates/ruff_python_parser/resources/inline/err/implicitly_concatenated_unterminated_string_multiline.py:4:1: SyntaxError: Expected an element of or the end of the f-string
---
> crates/ruff_python_parser/resources/inline/err/implicitly_concatenated_unterminated_string_multiline.py:4:1: SyntaxError: Expected an f-string or t-string element or the end of the f-string or t-string
34131c34131
< crates/ruff_python_parser/resources/inline/err/t_string_lambda_without_parentheses.py:2:15: SyntaxError: Expected an element of or the end of the t-string
---
> crates/ruff_python_parser/resources/inline/err/t_string_lambda_without_parentheses.py:2:15: SyntaxError: Expected an f-string or t-string element or the end of the f-string or t-string
```
So modulo color, the results are identical on 38,186 errors in our test
suite and CPython 3.10.
---------
Co-authored-by: David Peter <mail@david-peter.de>


Summary
This PR moves most of the work of rendering concise diagnostics in Ruff into
ruff_db, where the code is shared with ty. To accomplish this without breaking backwards compatibility in Ruff, there are two main changes on theruff_db/ty side:I don't think the notebook change failed any tests on its own, and only a handful of snaphots changed in ty after reordering the fields, but this will obviously affect any other uses of the concise format, outside of tests, too.
The other big change should only affect Ruff:
DisplayDiagnosticConfigoptionsMicha and I hoped that we could get by with one option (
hide_severity), but Ruff also togglesshow_fix_statusitself, independently (there are cases where we want neither severity nor the fix status), and during the implementation I realized we also needed access to anApplicability. The main goal here is to suppress the severity (errorabove) because ruff only uses theerrorseverity and to use the secondary/noqa code instead of the line name (invalid-assignmentabove).This part of the concise diagnostic is actually shared with the
fulloutput format in Ruff, but with the settings above, there are no snapshot changes to either format.Test Plan
Existing tests with the handful of updates mentioned above, as well as some new tests in the
concisemodule.Also this PR. Swapping the fields might have broken mypy_primer, unless it occasionally times out on its own.
I also ran this script in the root of my Ruff checkout, which also has CPython in it:
This yielded an expected diff due to some t-string error changes on main since 0.12.4:
So modulo color, the results are identical on 38,186 errors in our test suite and CPython 3.10.