Advanced Enumerations (compatible with Python's stdlib Enum), NamedTuples, and NamedConstants
76
Create an immutable set of payment status codes and helper utilities for looking them up by numeric value.
PENDING = 102, AUTHORIZED = 200, DECLINED = 402, REFUNDED = 209. Each status object exposes name and value properties matching these pairs. @teststatus_from_code(200) returns the status object for AUTHORIZED, and status_from_code(402) returns the one for DECLINED. Unknown codes raise ValueError. Repeated lookups for the same code return the same status object instance. @testPaymentStatus.PENDING = 0 or del PaymentStatus.DECLINED) raises AttributeError, leaving the original constants unchanged. @testlist_status_codes() returns a list of (name, value) tuples in definition order: [("PENDING", 102), ("AUTHORIZED", 200), ("DECLINED", 402), ("REFUNDED", 209)]. @test@generates
class PaymentStatus:
PENDING: int
AUTHORIZED: int
DECLINED: int
REFUNDED: int
def status_from_code(code: int) -> PaymentStatus:
"""Return the status constant for a numeric code or raise ValueError."""
def list_status_codes() -> list[tuple[str, int]]:
"""Return (name, value) pairs for all statuses in definition order."""Provides immutable constant groups with lookup and iteration 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