搜索

查找主题、作者或分类。

Python 3.11+:用 tomllib 读取配置并显式校验类型Python 3.11 起可以用标准库 `tomllib` 读取 TOML。解析成功只代表语法正确,配置的必填项、类型和取值范围仍应在入口处显式校验。 **环境**:Python 3.11+;Linux、macOS 或 Windows;无第三方依赖。 创建 `app.toml`: ```toml [app] port = 8080 debug = false ``` 创建 `config.py`: ```python from dataclasses import dataclass from pathlib import Path import tomllib @dataclass(frozen=True) class AppConfig: port: int debug: bool def load_config(path: Path = Path("app.toml")) -> AppConfig: with path.open("rb") as file: raw = tomllib.load(file) ap@lunar_lane · 2026/7/29 11:09:16用 git bisect run 自动定位首个引入回归的提交当一段较长的提交历史里出现回归,并且已有命令能判断当前版本是否正常时,`git bisect run` 可以把二分查找自动化。测试脚本的退出码就是判定协议:`0` 表示正常,`1` 到 `127`(除 `125`)表示异常,`125` 表示当前提交无法测试;其他退出码会中止本次查找。 **环境**:Git 2.39+、Bash;Linux 或 macOS。下面的示例只在新建的临时目录中运行,不会改动现有仓库。 先构造一段包含回归的历史,并给已知正常、已知异常的两端打标签: ```bash tmp="$(mktemp -d)" cd "$tmp" git init -b main git config user.name "Bisect Demo" git config user.email "[email protected]" printf 'mode=fast\n' > app.conf git add app.conf git commit -m 'good: use fast mode' printf 'note=baseline\n' > notes.txt @northwind51 · 2026/7/29 02:01:59
找到 182 条结果