tryceratops
v2.4.1
受此博客文章的啟發。我在這裡描述了此工具的建築過程。
“對於那些喜歡恐龍的人?除了塊以外,清潔嘗試/除外。”
概括
flake8插件 pip install tryceratops
或者
poetry add -D tryceratops
tryceratops [filename or dir...]
您可以通過運行來啟用實驗分析儀:
tryceratops --experimental [filename or dir...]
您可以通過使用以下方式忽略特定的違規行為: --ignore TRYXXX :
tryceratops --ignore TRY201 --ignore TRY202 [filename or dir...]
您可以通過使用以下方式排除DIRS: --exclude dir/path :
tryceratops --exclude tests --exclude .venv [filename or dir...]
您還可以自動違規:
tryceratops --autofix [filename or dir...]
flake8插件? Tryceratops也是flake8的插件,因此您可以:
❯ flake8 --select TRY src/tests/samples/violations/call_raise_vanilla.py
src/tests/samples/violations/call_raise_vanilla.py:13:9: TRY002 Create your own exception
src/tests/samples/violations/call_raise_vanilla.py:13:9: TRY003 Avoid specifying long messages outside the exception class
src/tests/samples/violations/call_raise_vanilla.py:21:9: TRY201 Simply use 'raise' without specifying exception object again
所有違規及其描述都可以在文檔中找到。
到目前為止,Autofix僅支持違規行為:TRY200,TRY201和TRY400。
如果您想忽略特定文件中的違規行為,則可以:
noqa的評論添加到您要忽略的文件頂部noqa的評論添加到您要忽略的行noqa: CODE的評論例子:
def verbose_reraise_1 ():
try :
a = 1
except Exception as ex :
raise ex # noqa: TRY202您可以為設置規則設置一個pyproject.toml文件。這對於避免一遍又一遍地重複使用相同的CLI標誌很有用,並有助於定義項目的結構。
例子:
[ tool . tryceratops ]
exclude = [ " samples " ]
ignore = [ " TRY002 " , " TRY200 " , " TRY300 " ]
experimental = false
check_pickable = false
allowed_base_exceptions = [ " MyAppBase " ]CLI標誌始終覆蓋配置文件。
如果您想使用預先承諾,請添加此信息:
- repo : https://github.com/guilatrova/tryceratops
rev : v2.4.1
hooks :
- id : tryceratops 將此精美的徽章添加到您項目的README.md中:
[ ![ try/except style: tryceratops ] ( https://img.shields.io/badge/try%2Fexcept%20style-tryceratops%20%F0%9F%A6%96%E2%9C%A8-black )] ( https://github.com/guilatrova/tryceratops ) 如果您想了解更多有關:
感謝您考慮為所有人提供更好的人!
請參閱貢獻文檔。
請參閱ChangElog。
麻省理工學院
感謝上帝的靈感? ☁️☀️
黑色項目的見解。