Advanced Enumerations (compatible with Python's stdlib Enum), NamedTuples, and NamedConstants
76
Build a small module that keeps dependency-based enums compatible with the standard library's enum module and makes them round-trip cleanly through SQLite.
enable_stdlib_bridge() makes DbEvent members pass isinstance checks against enum.Enum while still behaving as the dependency's enums; calling disable_stdlib_bridge() reverses that integration for subsequent checks. @testenable_stdlib_bridge() or disable_stdlib_bridge() do not raise and leave compatibility in the expected state. @testwrite_events() stores a sequence of DbEvent values into SQLite using parameter binding so that the database rows contain the enum names, and read_events() returns the same enum values in insertion order from that table. @test@generates
import sqlite3
from typing import Iterable, List
class DbEvent(...):
NEW = ...
RETRY = ...
COMPLETE = ...
def enable_stdlib_bridge() -> None:
"""Enable stdlib enum compatibility for DbEvent."""
def disable_stdlib_bridge() -> None:
"""Remove stdlib enum compatibility for DbEvent."""
def init_storage(conn: sqlite3.Connection) -> None:
"""Create/drop and prepare the SQLite table used for enum persistence."""
def write_events(conn: sqlite3.Connection, events: Iterable[DbEvent]) -> None:
"""Insert events into the backing table using parameter binding."""
def read_events(conn: sqlite3.Connection) -> List[DbEvent]:
"""Fetch events from the backing table as DbEvent values."""Provides enum helpers for stdlib compatibility toggling and SQLite binding 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