Skip to content

Commit 930768a

Browse files
committed
[PIE796] don't report when using ellipses for enum values in stub files
Fixes astral-sh#8818
1 parent 8365d2e commit 930768a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

crates/ruff_linter/src/rules/flake8_pie/rules/non_unique_enums.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use ruff_diagnostics::Diagnostic;
44
use ruff_diagnostics::Violation;
55
use ruff_macros::{derive_message_formats, violation};
66
use ruff_python_ast::comparable::ComparableExpr;
7-
use ruff_python_ast::{self as ast, Expr, Stmt};
7+
use ruff_python_ast::{self as ast, Expr, PySourceType, Stmt};
88
use ruff_text_size::Ranged;
99

1010
use crate::checkers::ast::Checker;
@@ -84,7 +84,15 @@ pub(crate) fn non_unique_enums(checker: &mut Checker, parent: &Stmt, body: &[Stm
8484
}
8585
}
8686

87-
if !seen_targets.insert(ComparableExpr::from(value)) {
87+
let comparable = ComparableExpr::from(value);
88+
89+
if checker.source_type == PySourceType::Stub
90+
&& comparable == ComparableExpr::EllipsisLiteral
91+
{
92+
continue;
93+
}
94+
95+
if !seen_targets.insert(comparable) {
8896
let diagnostic = Diagnostic::new(
8997
NonUniqueEnums {
9098
value: checker.generator().expr(value),

crates/ruff_python_ast/src/comparable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ pub enum ComparableExpr<'a> {
766766
NumberLiteral(ExprNumberLiteral<'a>),
767767
BoolLiteral(ExprBoolLiteral<'a>),
768768
NoneLiteral,
769-
EllispsisLiteral,
769+
EllipsisLiteral,
770770
Attribute(ExprAttribute<'a>),
771771
Subscript(ExprSubscript<'a>),
772772
Starred(ExprStarred<'a>),
@@ -964,7 +964,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
964964
Self::BoolLiteral(ExprBoolLiteral { value })
965965
}
966966
ast::Expr::NoneLiteral(_) => Self::NoneLiteral,
967-
ast::Expr::EllipsisLiteral(_) => Self::EllispsisLiteral,
967+
ast::Expr::EllipsisLiteral(_) => Self::EllipsisLiteral,
968968
ast::Expr::Attribute(ast::ExprAttribute {
969969
value,
970970
attr,

0 commit comments

Comments
 (0)