alunduil / alunduil/zfs-replicate

venn returns its three groups as a named record

オープン
#693 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
enhancement
主要言語
Python
スター
24
フォーク
6
平均マージ
3時間 11分
マージ済み PR(30日)
49

説明

## Summary

Give `zfs.replicate.list.venn` a return type that names its three groups, so
callers reach them by name rather than by position.

## Motivation

`venn` returns `tuple[list[T], list[T], list[T]]` (`zfs/replicate/list.py:22`).
All three elements have the same type, so nothing but the docstring maps a
position to a meaning: left-only, common, right-only.

The single caller unpacks it positionally and routes the groups to opposite
actions:

```python
lefts, middles, rights = venn(local_snaps, remote_snapshots[destination])

send_tasks = _send_snapshots(remote, lefts)
destroy_tasks = _destroy_snapshots(destination, rights)
```

Transposing `lefts` and `rights` there would generate destroy tasks for
snapshots that should be sent and send tasks for ones that should be destroyed.
mypy cannot catch it, because it sees three interchangeable `list[T]`.

Fowler's Replace Primitive with Object is the fix. Surfaced while reviewing #501
through the refactoring catalogue and declined there to keep that change to
annotation churn.

## Scope

- Add a `NamedTuple` to `zfs/replicate/list.py` whose fields carry the
docstring's vocabulary for the three groups.
- Return it from `venn`.
- Read the groups by name at `zfs/replicate/task/generate.py:39`.
- Update the three `venn` property tests in
`zfs_test/replicate_test/list_test.py`, which destructure the result.

## Acceptance criteria

- [ ] Transposing two groups at a call site is a type error rather than a
silent behaviour change.
- [ ] `task/generate.py` reads the groups by name.
- [ ] The docstring no longer has to explain what each component position means.

## Additional context

Martin Fowler, _Refactoring_ 2nd edition: Replace Primitive with Object.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Start with zfs/replicate/list.py:22 and inspect the caller at zfs/replicate/task/generate.py:39. Run the three venn property tests in zfs_test/replicate_test/list_test.py before and after the change. Done means the result exposes named groups, the caller reads those names, and positional group transposition is rejected by typing.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
cli
issue の種類
リファクタリング
難易度
3/5
見積もり時間
1〜2日
活発さ
活発
明瞭さ
明確に書かれている
初心者へのやさしさ
84/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。