Last active
June 11, 2021 19:05
-
-
Save kergoth/52b65bdc9948283a032ce8033c56c4ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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