Skip to content
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 collapsed-ellipsis bodies in other statements #8499

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pycodestyle/E70.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ class Foo:
#: E701:2:3
a = \
5;
#:
with x(y) as z: ...
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use ruff_source_file::Locator;
/// if foo == "blah":
/// do_blah_thing()
/// ```

///
/// [PEP 8]: https://peps.python.org/pep-0008/#other-recommendations
#[violation]
pub struct MultipleStatementsOnOneLineColon;
Expand Down Expand Up @@ -206,12 +206,13 @@ pub(crate) fn compound_statements(
{
colon = Some((range.start(), range.end()));

// Allow `class C: ...`-style definitions in stubs.
allow_ellipsis = class.is_some();
// Allow `class C: ...`-style definitions.
allow_ellipsis = true;
}
}
Tok::Semi => {
semi = Some((range.start(), range.end()));
allow_ellipsis = false;
}
Tok::Comment(..) | Tok::Indent | Tok::Dedent | Tok::NonLogicalNewline => {}
_ => {
Expand All @@ -223,6 +224,7 @@ pub(crate) fn compound_statements(

// Reset.
semi = None;
allow_ellipsis = false;
}

if let Some((start, end)) = colon {
Expand All @@ -245,6 +247,7 @@ pub(crate) fn compound_statements(
try_ = None;
while_ = None;
with = None;
allow_ellipsis = false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ E70.py:71:4: E703 [*] Statement ends with an unnecessary semicolon
70 | a = \
71 | 5;
| ^ E703
72 | #:
73 | with x(y) as z: ...
|
= help: Remove unnecessary semicolon

Expand All @@ -101,5 +103,7 @@ E70.py:71:4: E703 [*] Statement ends with an unnecessary semicolon
70 70 | a = \
71 |- 5;
71 |+ 5
72 72 | #:
73 73 | with x(y) as z: ...


Loading