Adopt a style rule that keeps code (1) concise in data derivation, (2) consistent in input normalization, and (3) correct in conditional logic by using the right source of state.

How to apply:

Example pattern:

from typing import Dict, List, Tuple

ModelOption = Tuple[str, str]
ProviderModeOptions = Dict[str, List[ModelOption]]

MODEL_OPTIONS: ProviderModeOptions = {...}

def get_known_models() -> Dict[str, List[str]]:
    # Concise derived-data construction
    return {
        provider: sorted({value for options in mode_options.values() for _, value in options})
        for provider, mode_options in MODEL_OPTIONS.items()
    }

def _ensure_str(v) -> str:
    # Centralized normalization for serialization/write paths
    if v is None:
        return ""
    if isinstance(v, list):
        return "\n".join(map(str, v))
    return str(v)

def write_text(path, content):
    with open(path, "w", encoding="utf-8") as f:
        f.write(_ensure_str(content))

Checklist: