Skip to content

False positive invalid-enum-extension for Enum parent class with annotations #8830

@rarredon

Description

@rarredon

Bug description

Pylint incorrectly flags an Enum inherited from a parent Enum which has annotations. This is useful when overriding __new__ or __init__ on the parent Enum to add extra data to the Enum members while also keeping the codebase typed. Example:

example.py

from enum import Enum


class ColorEnum(Enum):
    red: int
    green: int
    blue: int

    def __init__(self, red: int, green: int, blue: int) -> None:
        self.red = red
        self.green = green
        self.blue = blue

class Pastel(ColorEnum):
    SAGE = (170, 200, 167)

Configuration

No response

Command used

pylint example.py

Pylint output

************* Module example
example.py:14:0: E0244: Extending inherited Enum class "ColorEnum" (invalid-enum-extension)

Expected behavior

No output

Pylint version

pylint 2.17.4
astroid 2.15.5
Python 3.8.16 (default, Mar 15 2023, 13:36:46)
[Clang 14.0.0 (clang-1400.0.29.202)]

OS / Environment

macOS Ventura 13.2.1

Additional dependencies

No response

Metadata

Metadata

Labels

False Positive 🦟A message is emitted but nothing is wrong with the codeenum

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions