mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Allow compound statements of single ellipsis (#2837)
This allows `class C: ...`-style compound statements in stub files. Closes #2835.
This commit is contained in:
parent
83f6e52c92
commit
7dab4807d0
4 changed files with 57 additions and 0 deletions
|
@ -46,3 +46,11 @@ if a := 1:
|
|||
pass
|
||||
#:
|
||||
func = lambda x: x** 2 if cond else lambda x:x
|
||||
#:
|
||||
class C: ...
|
||||
#:
|
||||
def f(): ...
|
||||
#: E701:1:8 E702:1:13
|
||||
class C: ...; x = 1
|
||||
#: E701:1:8 E702:1:13
|
||||
class C: ...; ...
|
||||
|
|
|
@ -53,6 +53,10 @@ pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
|
|||
let mut while_ = None;
|
||||
let mut with = None;
|
||||
|
||||
// As a special-case, track whether we're at the first token after a colon.
|
||||
// This is used to allow `class C: ...`-style definitions in stubs.
|
||||
let mut allow_ellipsis = false;
|
||||
|
||||
// Track the bracket depth.
|
||||
let mut par_count = 0;
|
||||
let mut sqb_count = 0;
|
||||
|
@ -118,12 +122,17 @@ pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
|
|||
|| with.is_some()
|
||||
{
|
||||
colon = Some((start, end));
|
||||
allow_ellipsis = true;
|
||||
}
|
||||
}
|
||||
Tok::Semi => {
|
||||
semi = Some((start, end));
|
||||
}
|
||||
Tok::Comment(..) | Tok::Indent | Tok::Dedent | Tok::NonLogicalNewline => {}
|
||||
Tok::Ellipsis if allow_ellipsis => {
|
||||
// Allow `class C: ...`-style definitions in stubs.
|
||||
allow_ellipsis = false;
|
||||
}
|
||||
_ => {
|
||||
if let Some((start, end)) = semi {
|
||||
diagnostics.push(Diagnostic::new(
|
||||
|
|
|
@ -112,4 +112,24 @@ expression: diagnostics
|
|||
column: 15
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
MultipleStatementsOnOneLineColon: ~
|
||||
location:
|
||||
row: 54
|
||||
column: 7
|
||||
end_location:
|
||||
row: 54
|
||||
column: 8
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
MultipleStatementsOnOneLineColon: ~
|
||||
location:
|
||||
row: 56
|
||||
column: 7
|
||||
end_location:
|
||||
row: 56
|
||||
column: 8
|
||||
fix: ~
|
||||
parent: ~
|
||||
|
||||
|
|
|
@ -42,4 +42,24 @@ expression: diagnostics
|
|||
column: 11
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
MultipleStatementsOnOneLineSemicolon: ~
|
||||
location:
|
||||
row: 54
|
||||
column: 12
|
||||
end_location:
|
||||
row: 54
|
||||
column: 13
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
MultipleStatementsOnOneLineSemicolon: ~
|
||||
location:
|
||||
row: 56
|
||||
column: 12
|
||||
end_location:
|
||||
row: 56
|
||||
column: 13
|
||||
fix: ~
|
||||
parent: ~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue