mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-17 22:08:28 +00:00
[PIE796] don't report when using ellipses for enum values in stub files (#8825)
## Summary Just ignores ellipses as enum values inside stub files. Fixes #8818.
This commit is contained in:
parent
8365d2e0fd
commit
852a8f4a4f
7 changed files with 47 additions and 4 deletions
|
@ -64,3 +64,9 @@ class FakeEnum10(enum.Enum):
|
|||
A = enum.auto()
|
||||
B = enum.auto()
|
||||
C = enum.auto()
|
||||
|
||||
|
||||
class FakeEnum10(enum.Enum):
|
||||
A = ...
|
||||
B = ... # PIE796
|
||||
C = ... # PIE796
|
||||
|
|
7
crates/ruff_linter/resources/test/fixtures/flake8_pie/PIE796.pyi
vendored
Normal file
7
crates/ruff_linter/resources/test/fixtures/flake8_pie/PIE796.pyi
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
import enum
|
||||
|
||||
|
||||
class FakeEnum1(enum.Enum):
|
||||
A = ...
|
||||
B = ...
|
||||
C = ...
|
|
@ -21,6 +21,7 @@ mod tests {
|
|||
#[test_case(Rule::UnnecessarySpread, Path::new("PIE800.py"))]
|
||||
#[test_case(Rule::ReimplementedContainerBuiltin, Path::new("PIE807.py"))]
|
||||
#[test_case(Rule::NonUniqueEnums, Path::new("PIE796.py"))]
|
||||
#[test_case(Rule::NonUniqueEnums, Path::new("PIE796.pyi"))]
|
||||
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
|
|
|
@ -4,7 +4,7 @@ use ruff_diagnostics::Diagnostic;
|
|||
use ruff_diagnostics::Violation;
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::comparable::ComparableExpr;
|
||||
use ruff_python_ast::{self as ast, Expr, Stmt};
|
||||
use ruff_python_ast::{self as ast, Expr, PySourceType, Stmt};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
@ -84,7 +84,15 @@ pub(crate) fn non_unique_enums(checker: &mut Checker, parent: &Stmt, body: &[Stm
|
|||
}
|
||||
}
|
||||
|
||||
if !seen_targets.insert(ComparableExpr::from(value)) {
|
||||
let comparable = ComparableExpr::from(value);
|
||||
|
||||
if checker.source_type == PySourceType::Stub
|
||||
&& comparable == ComparableExpr::EllipsisLiteral
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if !seen_targets.insert(comparable) {
|
||||
let diagnostic = Diagnostic::new(
|
||||
NonUniqueEnums {
|
||||
value: checker.generator().expr(value),
|
||||
|
|
|
@ -57,4 +57,21 @@ PIE796.py:54:5: PIE796 Enum contains duplicate value: `2`
|
|||
| ^^^^^ PIE796
|
||||
|
|
||||
|
||||
PIE796.py:71:5: PIE796 Enum contains duplicate value: `...`
|
||||
|
|
||||
69 | class FakeEnum10(enum.Enum):
|
||||
70 | A = ...
|
||||
71 | B = ... # PIE796
|
||||
| ^^^^^^^ PIE796
|
||||
72 | C = ... # PIE796
|
||||
|
|
||||
|
||||
PIE796.py:72:5: PIE796 Enum contains duplicate value: `...`
|
||||
|
|
||||
70 | A = ...
|
||||
71 | B = ... # PIE796
|
||||
72 | C = ... # PIE796
|
||||
| ^^^^^^^ PIE796
|
||||
|
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_pie/mod.rs
|
||||
---
|
||||
|
|
@ -766,7 +766,7 @@ pub enum ComparableExpr<'a> {
|
|||
NumberLiteral(ExprNumberLiteral<'a>),
|
||||
BoolLiteral(ExprBoolLiteral<'a>),
|
||||
NoneLiteral,
|
||||
EllispsisLiteral,
|
||||
EllipsisLiteral,
|
||||
Attribute(ExprAttribute<'a>),
|
||||
Subscript(ExprSubscript<'a>),
|
||||
Starred(ExprStarred<'a>),
|
||||
|
@ -964,7 +964,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
Self::BoolLiteral(ExprBoolLiteral { value })
|
||||
}
|
||||
ast::Expr::NoneLiteral(_) => Self::NoneLiteral,
|
||||
ast::Expr::EllipsisLiteral(_) => Self::EllispsisLiteral,
|
||||
ast::Expr::EllipsisLiteral(_) => Self::EllipsisLiteral,
|
||||
ast::Expr::Attribute(ast::ExprAttribute {
|
||||
value,
|
||||
attr,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue