Skip to content

Commit

Permalink
[PIE796] don't report when using ellipses for enum values in stub files
Browse files Browse the repository at this point in the history
  • Loading branch information
sciyoshi committed Nov 23, 2023
1 parent 8365d2e commit 930768a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions crates/ruff_linter/src/rules/flake8_pie/rules/non_unique_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_python_ast/src/comparable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 930768a

Please sign in to comment.