Advanced Enumerations (compatible with Python's stdlib Enum), NamedTuples, and NamedConstants
76
A feature and permission module built around bitmask-based enumerations that combine, test, and round-trip flags without manual bit assignment.
Presets are built from single-bit members: DEFAULT = SEARCH | REPORTS, ANALYST = SEARCH | REPORTS | EXPORT, and ADMINISTRATOR = SEARCH | REPORTS | EXPORT | ADMIN.
enable_features yields a value where has_feature reports true for SEARCH, REPORTS, and EXPORT, and false for ADMIN. @testpermissions_from_int produces a value that represents READ and EXECUTE but not WRITE, and converting it back with permissions_to_int returns 5. @test@generates
from typing import Iterable
class FeatureFlag:
SEARCH: "FeatureFlag"
REPORTS: "FeatureFlag"
EXPORT: "FeatureFlag"
ADMIN: "FeatureFlag"
DEFAULT: "FeatureFlag"
ANALYST: "FeatureFlag"
ADMINISTRATOR: "FeatureFlag"
class AccessLevel:
READ: "AccessLevel"
WRITE: "AccessLevel"
EXECUTE: "AccessLevel"
FULL: "AccessLevel"
def enable_features(plan: FeatureFlag, extras: Iterable[FeatureFlag] | None = None) -> FeatureFlag:
"""Return a combined set of features from a base plan plus optional extras."""
def has_feature(active: FeatureFlag, feature: FeatureFlag) -> bool:
"""Check whether the active feature set includes the requested flag."""
def permissions_from_int(raw: int) -> AccessLevel:
"""Convert an integer mask into an access-level value."""
def permissions_to_int(level: AccessLevel) -> int:
"""Convert an access-level value back to its integer mask."""Advanced enumeration utilities with flag-style bitmask 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