Extension to the StrEnum class to add dict-like behaviour.
- Python 100%
| symbolic_constants | ||
| .gitignore | ||
| .python-version | ||
| LICENSE.md | ||
| pyproject.toml | ||
| README.md | ||
symbolic-constants
Extension of the StrEnum to class to enable some additional dictionary-like behaviour.
Usage
Subclass SymbolicConstant:
from symbolic_constants import SymbolicConstant
class MyConstant(SymbolicConstant):
ATTRIBUTE1: "attribute 1"
ATTRIBUTE2: "attribute 2"
Use as type hint in function definitions:
def foo(attr: MyConstant) -> MyConstant:
...
... or access the string literal directly:
a = foo(attr = MyConstant.ATTRIBUTE1)
Access all attributes in a dictionary like fashion:
MyConstant.values()
# Returns ['attribute 1', 'attribute 2']
MyConstant.keys()
# Returns ['ATTRIBUTE1', 'ATTRIBUTE2']
MyConstant.items()
# Returns [('ATTRIBUTE1', 'attribute 1'), ('ATTRIBUTE2', 'attribute 2')]