Conversation
|
|
We should respect the |
|
That makes sense to me. How does the approach of making the current I wasn't sure how many changes to put in this PR, but I think it definitely makes sense to wire it up somehow for useful tests. |
|
I'll convert to a draft because I think it's incomplete based on your suggestion. |
|
Hmm. I haven't really thought about it. We probably want to avoid calling |
|
Reopening for review. I added
Footnotes
|
MichaReiser
left a comment
There was a problem hiding this comment.
This is great! I suggest renaming the field on the setting structs to e.g. default_target_version or global_target_version so that its name raises questions: Hmm, why global? maybe this is not the field I want. Let me check the documentation
We should also test this feature in the editor. I think it currently doesn't work for the formatter.
AlexWaygood
left a comment
There was a problem hiding this comment.
I'll leave this one mostly to Micha, just a quick nit I spotted
| } | ||
|
|
||
| fn is_allowed_module(settings: &LinterSettings, module: &str) -> bool { | ||
| fn is_allowed_module(settings: &LinterSettings, minor_version: u8, module: &str) -> bool { |
There was a problem hiding this comment.
I'd prefer to pass around a PythonVersion in the ruff_linter crate where possible (only converting it to a u8 representing the minor version when crossing the crate boundary and calling a function from the ruff_python_stdlib crate) as it's more strongly typed
| fn is_allowed_module(settings: &LinterSettings, minor_version: u8, module: &str) -> bool { | |
| fn is_allowed_module(settings: &LinterSettings, version: PythonVersion, module: &str) -> bool { |
f8ab420 to
778c559
Compare
|
Wow I didn't know eliding the lifetime in a const was a recent feature. I thought clippy used to suggest that 🤷 Maybe I need to start building with 1.80 locally instead of 1.82... |
|
Thanks @MichaReiser for the thorough review. I think it's in a much better place now. The only open question I see now is how to add tests for the editor integration (if that's possible). I also feel like there might be a more elegant solution to the generic |
There are a few end to end tests in the VS code extension but it isn't something we have good infrastructure today. But @dhruvmanila knows better than I. |
I've talked with Brent in regards to this on Discord. Looking at the change that fixed the issue which you were pointing out earlier there are two options:
I'd suggest (1) but I'm longing to create a mock server xD |
|
Yes, thanks @dhruvmanila! I've added unit tests for It looks like notebooks also go through this code path, but I'm happy to add notebook-specific tests if either of you want. It shouldn't be too much trouble if I reuse the Similarly, it looks like linting goes straight through |
dhruvmanila
left a comment
There was a problem hiding this comment.
Thank you for adding those test cases in the language server, they look good.
* main: (38 commits) [red-knot] Use arena-allocated association lists for narrowing constraints (#16306) [red-knot] Rewrite `Type::try_iterate()` to improve type inference and diagnostic messages (#16321) Add issue templates (#16213) Normalize inconsistent markdown headings in docstrings (#16364) [red-knot] Better diagnostics for method calls (#16362) [red-knot] Add argfile and windows glob path support (#16353) [red-knot] Handle pipe-errors gracefully (#16354) Rename `venv-path` to `python` (#16347) [red-knot] Fixup some formatting in `infer.rs` (#16348) [red-knot] Restrict visibility of more things in `class.rs` (#16346) [red-knot] Add diagnostic for class-object access to pure instance variables (#16036) Add `per-file-target-version` option (#16257) [PLW1507] Mark fix unsafe (#16343) [red-knot] Add a test to ensure that `KnownClass::try_from_file_and_name()` is kept up to date (#16326) Extract class and instance types (#16337) Re-order changelog entries for 0.9.7 (#16344) [red-knot] Add support for `@classmethod`s (#16305) Update Salsa (#16338) Update Salsa part 1 (#16340) Upgrade Rust toolchain to 1.85.0 (#16339) ...
Summary
This PR is another step in preparing to detect syntax errors in the parser. It introduces the new
per-file-target-versiontop-level configuration option, which holds a mapping of compiled glob patterns to Python versions. I intend to use theLinterSettings::resolve_target_versionmethod here to pass to the parser:ruff/crates/ruff_linter/src/linter.rs
Lines 491 to 493 in f50849a
Test Plan
I added two new CLI tests to show that the
per-file-target-versionis respected in both the formatter and the linter.