Skip to content

Commit

Permalink
Allow duplicate enum values for enum.auto() (#1933)
Browse files Browse the repository at this point in the history
Closes #1932.
  • Loading branch information
charliermarsh authored Jan 17, 2023
1 parent 30e133f commit 70ea4b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion resources/test/fixtures/flake8_pie/PIE796.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum, unique


class FakeEnum(enum.Enum):
class FakeEnum1(enum.Enum):
A = "A"
B = "B"
C = "B" # PIE796
Expand Down Expand Up @@ -58,3 +58,9 @@ class FakeEnum9(enum.Enum):
A = "A"
B = "B"
C = "C"


class FakeEnum10(enum.Enum):
A = enum.auto()
B = enum.auto()
C = enum.auto()
9 changes: 9 additions & 0 deletions src/rules/flake8_pie/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ where
continue;
};

if let ExprKind::Call { func, .. } = &value.node {
if checker
.resolve_call_path(func)
.map_or(false, |call_path| call_path == ["enum", "auto"])
{
continue;
}
}

if !seen_targets.insert(ComparableExpr::from(value)) {
let diagnostic = Diagnostic::new(
violations::PreferUniqueEnums {
Expand Down

0 comments on commit 70ea4b2

Please sign in to comment.