Skip to content

non-unique-enums (PIE796): false positive #16868

@g-braeunlich

Description

@g-braeunlich

Summary

Example:

import enum
from enum import Enum


class E(Enum):
    A = enum.auto(), 0
    B = enum.auto(), 1
    C = enum.auto(), 0 # <- false positive here

    def __init__(self, uid: int, flag: int) -> None:
        self.uid = uid
        self.flag = flag


print(E.A.value)
print(E.C.value)
print(E.A.value == E.C.value)

Output:

(1, 0)
(3, 0)
False

So cleary in this example, the values are unique, but still this rule warns about an enum with duplicated value:

PIE796 Enum contains duplicate value: `enum.auto(), 0`
   |
 6 |     A = enum.auto(), 0
 7 |     B = enum.auto(), 1
 8 |     C = enum.auto(), 0
   |     ^^^^^^^^^^^^^^^^^^ PIE796
 9 |
10 |     def __init__(self, uid: int, flag: int) -> None:
   |

Version

ruff 0.9.10

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghelp wantedContributions especially welcome

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions