-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[syntax-errors] return
outside function
#17300
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
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.
|
@@ -254,7 +254,8 @@ impl<'src> Parser<'src> { | |||
} | |||
|
|||
// test_ok simple_stmts_with_semicolons | |||
// return; import a; from x import y; z; type T = int | |||
// def outer(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think the function names don't matter here so would prefer to just keep it _
e9c9ed8
to
44a043b
Compare
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 |
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.