Skip to content

When inheriting an enum, WPS115 occurs. #3497

@imtoopunkforyou

Description

@imtoopunkforyou

What's wrong

If you use upper case in enum classes, then everything is fine, WPS does not swear.

import enum


class CommandsConfigureEnum(enum.Enum):
    """Some docstr."""

    VERBOSE = ('-v', '--verbose')
    SILENT = ('-s', '--silent')
    INSECURE = ('-k', '--insecure')
    LOCATION = ('-L', '--location')
    INCLUDE = ('-i', '--include')

But if you use inheritance, then problems begin.

import enum


class Commands(enum.Enum):
    """Some docstr."""

    def __init__(
        self,
        short: str,
        long: str,
    ) -> None:
        self._short = short
        self._long = long

    @property
    def short(self) -> str:
        """Short form."""
        return self._short

    @property
    def long(self) -> str:
        """Long form."""
        return self._long

    def get(self, *, shorted: bool) -> str:
        """Returns curl command."""
        return self.short if shorted else self.long


class CommandsConfigureEnum(Commands):
    """Some docstr."""

    VERBOSE = ('-v', '--verbose')
    SILENT = ('-s', '--silent')
    INSECURE = ('-k', '--insecure')
    LOCATION = ('-L', '--location')
    INCLUDE = ('-i', '--include')


class CommandsTransferEnum(Commands):
    """Some docstr."""

    SEND_DATA = ('-d', '--data')
    HEADER = ('-H', '--header')
    REQUEST = ('-X', '--request')
    FORM = ('-F', '--form')

at this point, I catch the WPS115 error.

How it should be

Even with enum inheritance WPS115 should not occur

Flake8 version and plugins

{
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.10.18",
    "system": "Darwin"
  },
  "plugins": [
    {
      "plugin": "mccabe",
      "version": "0.7.0"
    },
    {
      "plugin": "pycodestyle",
      "version": "2.14.0"
    },
    {
      "plugin": "pyflakes",
      "version": "3.4.0"
    },
    {
      "plugin": "wemake-python-styleguide",
      "version": "1.3.0"
    }
  ],
  "version": "7.3.0"
}

pip information

OS information

MacBook Pro (14-inch, 2021)
macOS Sonoma 14.6.1 arm64

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions