alunduil / alunduil/zfs-replicate

SNAPSHOTS builds Snapshot directly instead of mapping a fixed dictionary

未關閉 適合新手
#655 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
enhancement good first issue
主要語言
Python
星號
24
分支
6
平均合併
3 小時 11 分鐘
30 天內合併 PR
49

描述

## User story

As a **contributor changing the snapshot strategies**, I want **`SNAPSHOTS` to name the type it constructs** so that **the strategy reads as "draw a `Snapshot` from these fields" rather than "draw a dict, then splat it into a constructor"**.

## Why

`zfs_test/replicate_test/snapshot_test/strategies.py` composes `SNAPSHOTS` in two steps (shown as it stands on #654, which renames the character set):

```python
_SNAPSHOTS_DICT: Dict[str, SearchStrategy[Any]] = {
"filesystem": _FILESYSTEMS,
"name": text(_ROUND_TRIP_SAFE),
"timestamp": integers(),
"previous": none(),
}
SNAPSHOTS = fixed_dictionaries(_SNAPSHOTS_DICT).map(lambda kwargs: Snapshot(**kwargs))
```

`hypothesis.strategies.builds` expresses the same draw as one expression:

```python
SNAPSHOTS = builds(
Snapshot,
filesystem=_FILESYSTEMS,
name=text(_ROUND_TRIP_SAFE),
timestamp=integers(),
previous=none(),
)
```

That retires a variable with one use, its `Dict[str, SearchStrategy[Any]]` annotation, the splat lambda, and the `Any`, `Dict`, `SearchStrategy`, and `fixed_dictionaries` imports that exist only to serve them. In Fowler's terms: Substitute Algorithm on `SNAPSHOTS`, subsuming an Inline Variable on `_SNAPSHOTS_DICT`.

What the change does not buy is static checking of the field names. mypy 2.3.1 under `strict = true` accepts a misspelled keyword in both shapes, checked against a scratch copy of each on 2026-08-21, so a typo stays a runtime `TypeError` either way. Readability is the whole payoff, which is worth saying out loud before someone reaches for `builds` expecting more.

## Acceptance criteria

- [ ] `SNAPSHOTS` is a single `builds(Snapshot, ...)` expression.
- [ ] `_SNAPSHOTS_DICT` and the imports that only served it are gone.
- [ ] The suite passes with no expectation changes, `test_snapshots_vary_filesystem` included, since the draws are meant to be equivalent.

## Out of scope

- The `f"a{x}"` fix and the naming that came with it (#405, #654).
- Giving other strategies modules the same treatment, and the per-symbol test classes in #486.

## Notes

- Target release: none — test-only, no behaviour change.
- Source: review of #654.

貢獻指南

開啟貢獻指南

研究方向

Start in zfs_test/replicate_test/snapshot_test/strategies.py, where SNAPSHOTS is currently built from _SNAPSHOTS_DICT and mapped into Snapshot. Replace that with the single builds(Snapshot, ...) expression shown in the issue, then remove _SNAPSHOTS_DICT and imports used only by it. Done means the suite passes without expectation changes, including test_snapshots_vary_filesystem.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
testing
Issue 類型
重構
難度
1/5
預估耗時
1 小時以內
活躍度
活躍
描述清晰度
描述清楚
新手友好度
92/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。