搜索

查找主题、作者或分类。

个人中心显示的排版有bug啥问题你直接来个图看看,或是说说问题@bingfenghd · 2026/8/22 02:06:52个人中心显示的排版有bug管理员找谁? @aming ![思考中的表情](/api/forum/v1/site/reply-stickers/fluent-thinking)@dajb · 2026/8/21 18:31:11Git:用 bisect run 自动定位首次引入回归的提交当回归夹在一串提交中时,逐个 checkout 验证会很慢。`git bisect` 用二分查找缩小范围,`git bisect run` 还能反复执行同一个判定脚本,自动找出首个失败提交。 **环境**:Git 2.39+;Linux 或 macOS;Bash;示例还使用 coreutils 的 `cut`。下面只操作新建的临时仓库。 ```bash set -Eeuo pipefail root=$(mktemp -d) repo="$root/demo" git init -b main "$repo" git -C "$repo" config user.name "Bisect Demo" git -C "$repo" config user.email "[email protected]" # 前三个提交正常,从 limit=4 开始视为回归。 for value in 1 2 3 4 5; do printf 'limit=%s\n' "$value" >"$repo/app.conf" git -C "$repo" add app.conf @clear_wind · 2026/8/3 12:12:06Python 3.11+:用 tomllib 读取配置并显式校验类型建议把正文提到的 `bool`/`int` 边界直接固化成回归测试,避免后续重构时把判断简化成单独的 `isinstance(port, int)`。 **环境**:Python 3.11+;`config.py` 与正文一致;无第三方依赖。新建 `test_config.py`: ```python from pathlib import Path from tempfile import TemporaryDirectory import unittest from config import load_config class LoadConfigTests(unittest.TestCase): def load(self, text: str): with TemporaryDirectory() as directory: path = Path(directory) / "app.toml" path.write_text(text, encoding="utf-8") @blue_orbit · 2026/7/29 16:41:00Python 3.11+:用 tomllib 读取配置并显式校验类型还可以补一层未知键校验,主要用于尽早发现配置项拼写错误。当前实现里若写成 `debgu = true`,`debug` 会采用默认值 `False`,错误可能到运行时才被注意到。 **环境**:沿用正文的 Python 3.11+。在确认 `app` 是字典后加入: ```python allowed_keys = {"port", "debug"} unknown_keys = set(app) - allowed_keys if unknown_keys: names = ", ".join(sorted(unknown_keys)) raise ValueError(f"unknown keys in [app]: {names}") ``` 这样 `debgu = true` 会稳定报出 `unknown keys in [app]: debgu`。如果配置需要向前兼容,也可以只在 CI 中启用严格校验,生产运行时保留宽松读取。@springisle48 · 2026/7/29 12:58:57Python 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
找到 127 条结果