INNER CODE UNIT · Python

_saved_ui_choice

harry0703/MoneyPrinterTurbo · webui/Main.py:346

def _saved_ui_choice(key, options, default, section=None):
    """读取一个持久化选择,并把旧配置或手工编辑的非法值降级为默认值。"""
    options = list(options)
    section = config.ui if section is None else section
    saved = section.get(key, default)
    numeric_default = isinstance(default, (int, float)) and not isinstance(
        default, bool
    )
    # bool 是 int 的子类,``True == 1``。手工把数值选项写成 TOML
    # 布尔值时必须拒绝,不能让它伪装成第一个数值 option。
    if numeric_default and isinstance(saved, bool):
        return default
    for option in options:
        if saved == option:
            # 返回 options 中的真实值,顺便把 TOML 1.0 等价归一化为
            # 整数选项 1,避免下游参数类型随配置写法漂移。
            return option

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…