Coverage for src / lexigram / contracts / feature_flags / models.py: 100%
21 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-19 05:41 +0800
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-19 05:41 +0800
1"""Feature flag value models for the Lexigram Framework.
3Defines the data types used when evaluating feature flags, including
4the flag type enum, value type alias, and full evaluation result.
5"""
7from __future__ import annotations
9from dataclasses import dataclass, field
10from enum import StrEnum
11from typing import Any
14class FlagType(StrEnum):
15 """The evaluation strategy of a feature flag."""
17 BOOLEAN = "boolean"
18 PERCENTAGE = "percentage"
19 USER_LIST = "user_list"
20 USER_ATTRIBUTE = "user_attribute"
21 TIME_BASED = "time_based"
22 VARIANT = "variant"
25# Type alias for the value returned by flag evaluation.
26# Simple flags → bool; percentage/variant flags → str | bool | float.
27FlagValue = bool | str | float
30@dataclass(frozen=True)
31class FlagEvaluation:
32 """The result of evaluating a single feature flag.
34 Attributes:
35 key: The flag identifier.
36 value: The evaluated value (type depends on FlagType).
37 flag_type: The type of flag evaluated.
38 reason: Machine-readable reason code (e.g. "DEFAULT", "TARGETING").
39 variant: Variant key for VARIANT-type flags, None otherwise.
40 metadata: Arbitrary evaluation metadata from the provider.
41 """
43 key: str
44 value: FlagValue
45 flag_type: FlagType = FlagType.BOOLEAN
46 reason: str = "DEFAULT"
47 variant: str | None = None
48 metadata: dict[str, Any] = field(default_factory=dict)
51__all__ = [
52 "FlagEvaluation",
53 "FlagType",
54 "FlagValue",
55]