Prompt
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:
- Prefer comprehensions/derived-data builders to remove boilerplate while preserving readability (e.g., building known model lists from a catalog).
- Centralize common type/format normalization into a single helper and use it at every call site that writes/serializes text. This avoids duplicated conversions and drift.
- When updating status/sections, ensure conditionals use the intended scope (current chunk vs accumulated buffer). Remove branches that depend on outdated or redundant state.
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:
- Did you simplify derived-data code without obscuring intent?
- Is there a single helper used everywhere for text normalization?
- Do your conditionals reference the correct “source of truth” for the decision being made?