【Black produced different code on the second pass of the formatter】

【Black produced different code on the second pass of the formatter】,第1张

INTERNAL ERROR: Black produced different code on the second pass of the formatter.
  • pre-commit遇到black和flake8冲突的解决办法
    • 环境说明
    • 有问题的代码块
    • 解决办法,顺序执行三步

pre-commit遇到black和flake8冲突的解决办法

Git是程序员协同开发中必不可少的一项工具,每个人都会在不同或者同一个分支上上传自己的代码,那么拥有一个代码规范就显得很必要了。
在Python中,pre-commit 官方网址就实现了这一功能。当我们进行git add 自己的文件时,运用pre-commit run进行代码规范检查。

环境说明

pre-commit:2.2.0
isort: 5.10.1
mypy:0.770
flake8:3.7.9
black:19.10b0
python:3.7.5
Ubuntu2004、VScode Editor

有问题的代码块


添加好修改过的代码后,执行pre-commit run 报错如下:

解决办法,顺序执行三步

`$ black --fast -l 87 blacktest.py
reformatted blacktest.py
All done! ✨ 🍰 ✨
1 file reformatted.

$ black --fast blacktest.py
reformatted blacktest.py
All done! ✨ 🍰 ✨
1 file reformatted.

$ black --diff blacktest.py
All done! ✨ 🍰 ✨
1 file would be left unchanged.`

因此,为了获得适当的解决方法,请使用 -l 87 执行第一个 --fast black!

最后执行 pre-commit run 问题解决


更多black报错问题请参阅black issues
书写不易,点个赞再走吧,有问题评论区留言,每天22点准时回复。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/873423.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-13
下一篇2022-05-13

发表评论

登录后才能评论

评论列表(0条)

    保存