aboutsummaryrefslogtreecommitdiff
path: root/poker/utils/enum.py
blob: 91e83a58f03ba83467bf7ab6e463ec3af31fcbd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from enum import StrEnum
from typing import Any


class AutoName(StrEnum):
    """Use the lower case name as the value for Python Enum (default would be integers).

    Inherits from str to ensure all types are string and as a bonus it becomes JSON
    serializable.

    See here for more information:
    https://docs.python.org/3/library/enum.html#using-automatic-values
    """

    def __str__(self) -> str:
        """Return string representation."""
        return str(self.value)

    @staticmethod
    def _generate_next_value_(
        name: str, start: int, count: int, last_values: list[Any]
    ) -> str:
        """Enum standard structure - the next value.

        See this on @staticmethod: https://github.com/python/mypy/issues/7591
        """
        return name.lower()