0
1

More than 1 year has passed since last update.

BlackをPython 3.10で使う

Posted at

tl;dr

  • コマンドライン black 〜 --target-version py310
  • pyproject.toml
pyproject.toml
[tool.black]
target-version = ['py310']

はじめに:Blackはデフォルトだとmatch文のparseに失敗する

Python 3.10になりmatch文が追加されました。
Blackも21.11b1から対応しましたが、デフォルトだとmatch文のparseに失敗するようになっているため、match文を含むソースコードファイルのフォーマットに失敗します。

解決:実行時オプション target-version をつける

target-versionをつけましょう。

black 〜 --target-version py310

Poetryを使っていてpyproject.tomlに設定値を書いている場合は

pyproject.toml
[tool.black]
target-version = ['py310']

としましょう。

おわりに

以上です。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1