Advanced Enumerations (compatible with Python's stdlib Enum), NamedTuples, and NamedConstants
76
Design an enumeration that models application access scopes while carefully controlling which attributes become members and which stay as helpers.
registry (code-to-label map built from real scopes) and _cache stay accessible but never appear in __members__ or iteration. @test.value equals the number of real scopes (3), derived from the current members rather than hard-coded. @testAUDIT_PREFIX returns the string "access:"; attempts to reassign or delete it raise AttributeError; it is not counted as an enum member. @testlabel giving "Admin", "Editor", "Viewer"; it coexists with the stored raw code without shadowing iteration or member lookup. @test@generates
from typing import Dict
class AccessScope(Enum):
AUDIT_PREFIX: str
registry: Dict[str, str]
ADMIN: "AccessScope"
EDITOR: "AccessScope"
VIEWER: "AccessScope"
TOTAL_COUNT: "AccessScope"
def __init__(self, code: str, label: str): ...
@property
def code(self) -> str: ...
@property
def label(self) -> str: ...
def is_elevated(self) -> bool: ...
def describe(self) -> str: ...Provides descriptor-based helpers for controlling enum membership, constants, and properties.
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