Merged
Conversation
Summary -- This PR reimplements [yield-outside-function (F704)](https://docs.astral.sh/ruff/rules/yield-outside-function/) as a semantic syntax error. Despite the name, this rule covers `yield from` and `await` in addition to `yield`. Test Plan -- Simple, new inline tests, along with the existing F704 test. A huge number of existing parser tests also had to be updated. These are all in the second commit. For `test_err` cases, I mostly just accepted the new semantic errors alongside the existing syntax errors. For `test_ok` cases, I either deleted the lines with new errors, or nested the offending lines in a function. I think I only deleted lines from the first two inline tests I updated, and all of the other fixtures should be nested. The `await` cases should actually be nested inside of `async` functions, but I've intentionally left them as synchronous functions for now because I'm planning to implement that check next.
Summary -- This PR reimplements [return-outside-function (F706)](https://docs.astral.sh/ruff/rules/return-outside-function/) as a semantic syntax error. These changes are very similar to those in #17298, which this is currently stacked on. Test Plan -- Simple new inline tests, as well as updates to existing tests in the second commit.
18 tasks
Contributor
|
dhruvmanila
reviewed
Apr 8, 2025
|
|
||
| // test_ok simple_stmts_with_semicolons | ||
| // return; import a; from x import y; z; type T = int | ||
| // def outer(): |
Member
There was a problem hiding this comment.
nit: I think the function names don't matter here so would prefer to just keep it _
dhruvmanila
approved these changes
Apr 8, 2025
MichaReiser
approved these changes
Apr 9, 2025
e9c9ed8 to
44a043b
Compare
Contributor
Author
|
Could I get one more quick review here? Like in #17298, I reverted the parser snapshot changes and moved everything to a linter test. It's much, much smaller now. The function scope tracking is now on the |
MichaReiser
approved these changes
Apr 11, 2025
dhruvmanila
approved these changes
Apr 11, 2025
crates/ruff_linter/resources/test/fixtures/syntax_errors/return_outside_function.py
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR reimplements return-outside-function (F706) as a semantic syntax error.
These changes are very similar to those in #17298.
Test Plan
New linter tests, plus existing F706 tests.