Skip to content

Conversation

@ntBre
Copy link
Contributor

@ntBre ntBre commented Apr 8, 2025

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.

ntBre added 5 commits April 8, 2025 13:58
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.
@ntBre ntBre added the rule Implementing or modifying a lint rule label Apr 8, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@ntBre ntBre marked this pull request as ready for review April 8, 2025 20:59

// test_ok simple_stmts_with_semicolons
// return; import a; from x import y; z; type T = int
// def outer():
Copy link
Member

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 _

@ntBre ntBre force-pushed the brent/syn-yield-outside-function branch 2 times, most recently from e9c9ed8 to 44a043b Compare April 10, 2025 17:04
Base automatically changed from brent/syn-yield-outside-function to main April 11, 2025 14:16
@ntBre
Copy link
Contributor Author

ntBre commented Apr 11, 2025

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 Context too, of course.

@ntBre ntBre enabled auto-merge (squash) April 11, 2025 17:03
@ntBre ntBre merged commit da32a83 into main Apr 11, 2025
18 checks passed
@ntBre ntBre deleted the brent/syn-return-outside-function branch April 11, 2025 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants