-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Allow passing ParseOptions
to inline tests
#16357
base: main
Are you sure you want to change the base?
Conversation
I initially tried passing the target version to all of the parser functions, but this required a huge number of changes. The downside of the current approach is that we're likely to accumulate quite a large Vec<SyntaxError> in the parser, only to filter it down later. The upside is that we don't have to fix every single call site of every parser function right now
could be Copy as well, currently because Mode and PythonVersion are
This reverts commit 3f43c82. This didn't work because the fuzzing only runs with cfg(test) not cfg(fuzzing)
d2950d6
to
ef8c37e
Compare
CodSpeed Performance ReportMerging #16357 will not alter performanceComparing Summary
|
I rebased on #16090 to get the new I made |
My other branch must be missing Doug's alist changes, at least I assume that's where the codspeed failure is coming from. I expect that to go away when I change the base branch to |
This PR is the first in a series derived from #16308, each of which add support for detecting one version-related syntax error from #6591. This one should be the largest because it also includes a couple of additional changes: 1. the `syntax_errors!` macro, which makes adding more variants a bit easier 2. the `Parser::add_unsupported_syntax_error` method Otherwise I think the general structure will be the same for each syntax error: * Detecting the error in the parser * Inline parser tests for the new error * New ruff CLI tests for the new error Because of the second point here, this PR is currently stacked on #16357. As noted above, there are new inline parser tests, as well as new ruff CLI tests. Once #16379 is resolved, there should also be new mdtests for red-knot, but this PR does not currently include those.
While trying to use this branch as a base for detecting some syntax errors, I realized that I forgot to actually check for the new errors in the valid syntax case. It's difficult to test this case because it requires a version-related syntax error in a |
This PR is the first in a series derived from #16308, each of which add support for detecting one version-related syntax error from #6591. This one should be the largest because it also includes a couple of additional changes: 1. the `syntax_errors!` macro, which makes adding more variants a bit easier 2. the `Parser::add_unsupported_syntax_error` method Otherwise I think the general structure will be the same for each syntax error: * Detecting the error in the parser * Inline parser tests for the new error * New ruff CLI tests for the new error Because of the second point here, this PR is currently stacked on #16357. As noted above, there are new inline parser tests, as well as new ruff CLI tests. Once #16379 is resolved, there should also be new mdtests for red-knot, but this PR does not currently include those.
## Summary This PR builds on the changes in #16220 to pass a target Python version to the parser. It also adds the `Parser::unsupported_syntax_errors` field, which collects version-related syntax errors while parsing. These syntax errors are then turned into `Message`s in ruff (in preview mode). This PR only detects one syntax error (`match` statement before Python 3.10), but it has been pretty quick to extend to several other simple errors (see #16308 for example). ## Test Plan The current tests are CLI tests in the linter crate, but these could be supplemented with inline parser tests after #16357. I also tested the display of these syntax errors in VS Code:   --------- Co-authored-by: Alex Waygood <[email protected]>
Based on a discussion with @MichaReiser on Discord, I backed out the This avoids needing to run the parser integration tests with the |
This PR is the first in a series derived from #16308, each of which add support for detecting one version-related syntax error from #6591. This one should be the largest because it also includes a couple of additional changes: 1. the `syntax_errors!` macro, which makes adding more variants a bit easier 2. the `Parser::add_unsupported_syntax_error` method Otherwise I think the general structure will be the same for each syntax error: * Detecting the error in the parser * Inline parser tests for the new error * New ruff CLI tests for the new error Because of the second point here, this PR is currently stacked on #16357. As noted above, there are new inline parser tests, as well as new ruff CLI tests. Once #16379 is resolved, there should also be new mdtests for red-knot, but this PR does not currently include those.
Summary
The changes here are based on the similar behavior in biome's
collect_tests
function, which allows a syntax for inline test headers likeBefore this PR, we only allowed headers of the form
label name
, wherelabel
is eithertest_err
ortest_ok
andname
is the name of the test. This PR adds support for an optional, trailingoptions
field, corresponding to JSON-serializedParseOptions
. These get written to a*.options.json
file alongside the inline test script and read when that test is run.This is currently stacked on #16090 so that I had something to test.
I wanted to add
serde
as a dev dependency only, but since these are run as integration tests, I had to add it as a full dependency. For this exact use case, we could just parse a trailing version string like "3.10" but I thought we might want the fullParseOptions
for the future.Test Plan
Existing inline tests, plus two new inline tests for
match-before-py310
.