使用
Linux x86_64
透過 uv tool 安裝 matchify
uv tool install matchify
確認能用
matchify --help輸出應包含「Convert if/elif/else chains to Python 3.10+ match statements」。
先試試這個
mkdir -p proj && cat > example_simple.py <<'PY'
x = 2
if x == 1:
print("one")
elif x == 2:
print("two")
else:
print("other")
PY
cat > example_format.py <<'PY'
# leading comment preserved?
x = 1 # inline comment
if x == 1: # branch comment
print("one") # action comment
elif x == 2:
print("two")
else:
print("other") # else comment
PY
cat > example_safe.py <<'PY'
x = 1
y = 2
if x == 1:
print("x is one")
elif y == 2:
print("y is two")
else:
print("other")
PY
cat proj/a.py <<'PY'
x = 1
if x == 1:
print("one")
elif x == 2:
print("two")
else:
print("other")
PY
cat proj/b.py <<'PY'
y = "a"
if y == "a":
print("a")
elif y == "b":
print("b")
else:
print("other")
PY
ls -Rcat > proj/a.py <<'PY'
x = 1
if x == 1:
print("one")
elif x == 2:
print("two")
else:
print("other")
PY
cat > proj/b.py <<'PY'
y = "a"
if y == "a":
print("a")
elif y == "b":
print("b")
else:
print("other")
PY
ls -R && cat example_simple.py && cat example_safe.pymatchify example_simple.py --check執行 matchify <file> --check 以 diff 預覽 Python 檔案的變更。
它能做什麼
- 將 if/elif/else 鏈轉換為 match 陳述式已測試
怎麼使用
- 執行
matchify <file> --check以 diff 預覽轉換結果。 - 找到
+match開頭的行查看新的 match 陳述式。
- 執行
- 轉換時保留註解與格式已測試
怎麼使用
- 對含有註解的檔案執行
matchify <file> --check。 - 檢查 diff,確認註解有被保留。
- 對含有註解的檔案執行
- 平行處理大型程式碼庫沒有看到它可用
- 僅在行為不變時才轉換未測試
pickfit 測到哪一步
Linux x86_64
- 可以安裝
- 可以啟動
- 4 項功能中 2 項可用
- 可離線使用
適合用來
- 將 if elif else 鏈轉換為 match 陳述式
- 以 diff 預覽轉換而不寫入
pickfit 怎麼測的
每次測試都從乾淨的機器開始,照上面的步驟執行。 pickfit 怎麼驗證
Linux x86_64
主要功能可用
- 從頭重跑
- 可離線使用
- 檢查於 2026年11月1日
- 版本 0.3.0
測試機器遇到的差異
- README: --check only reports them as diffs
測試中: --check 在有可轉換項目時會以 1 結束(依 README),因此轉換檢查中 exit 1 代表成功