Skip to content

Instantly share code, notes, and snippets.

@kergoth
Last active June 11, 2021 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kergoth/52b65bdc9948283a032ce8033c56c4ab to your computer and use it in GitHub Desktop.
Save kergoth/52b65bdc9948283a032ce8033c56c4ab to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from enum import auto
from enum import Enum
from typing import Any, List
class AutoNameValue(Enum):
"""Set the enumeration values to their names."""
@staticmethod
def _generate_next_value_(
name: str, start: int, count: int, last_values: List[Any]
) -> str:
return name
class Colour(AutoNameValue):
RED = auto()
GREEN = auto()
BLUE = auto()
def __str__(self) -> str:
"""Return the name of the enumeration, not its context."""
return self.name
assert str(Colour.RED) == "red"
assert str(Colour.RED.name) == "red"
assert str(Colour.RED.value) == "red"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment