Advanced Enumerations (compatible with Python's stdlib Enum), NamedTuples, and NamedConstants
76
Build a small utility that generates enumeration types for access levels at runtime and provides helpers for resolving and listing those levels.
(name, value) pairs, create an enumeration type whose members and order mirror the provided pairs; reject duplicate names or values. @testresolve_level returns the matching member when given either a member name string (case-sensitive) or its numeric value; it raises ValueError for invalid queries. @testlist_levels returns a list of (name, value) tuples reflecting the enumeration's iteration order. @test@generates
from typing import Iterable, Tuple, Union, Any
def create_level_enum(levels: Iterable[Tuple[str, int]]):
"""Return an enumeration type whose members and order match the provided pairs; reject duplicate names or values."""
def resolve_level(level_enum: Any, query: Union[str, int]):
"""Return the enumeration member matching a name or value; raise ValueError if the query is invalid."""
def list_levels(level_enum: Any):
"""Return a list of (name, value) pairs in the enumeration's iteration order."""Provides advanced enumeration support.
Install with Tessl CLI
npx tessl i tessl/pypi-aenumevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10