Define type for enum and complex dictionary



examples/python-types-at-pyweb-2025-01/defined_types.py
from typing import Literal
LevelType = Literal["debug", "info", "warning"]

size: LevelType = "debug"
#size = "error"

# ------------------------------------------

from datetime import datetime
from typing import TypedDict
HistoryType = TypedDict('HistoryType', {
    "date" : datetime,
    "level": LevelType,
    "text": str,
})

event: HistoryType = {
        "date": datetime.now(),
        "level": "debug",
        "text": "Demo typing",
}