V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
mimzy
V2EX  ›  Python

代码格式化工具 Black 发布首个稳定版

  •  
  •   mimzy ·
    mookrs · 2022-02-09 13:01:25 +08:00 · 3166 次点击
    这是一个创建于 807 天前的主题,其中的信息可能已经有所发展或是发生改变。
    https://github.com/psf/black/releases/tag/22.1.0

    10 天前发布的,终于不 beta 了。我应该是从 19.x 开始用的,配合 isort 再也没操心过格式化问题。
    5 条回复    2022-02-13 23:57:17 +08:00
    warcraft1236
        1
    warcraft1236  
       2022-02-09 14:17:48 +08:00
    我也在用,但是其他人觉得他格式化的规则有些东西不太能接受
    weakish
        2
    weakish  
       2022-02-10 18:09:25 +08:00
    一直在用。但是稳定版「 Remove Python 2 support 」, 糟糕,看来要换工具了,头疼。
    mimzy
        3
    mimzy  
    OP
       2022-02-10 20:08:08 +08:00 via Android
    @weakish 继续用 Black 老版本问题不大。另外如果不是特别难迁移的项目 还是升级吧…连 3.6 都 end of life 了
    ClericPy
        4
    ClericPy  
       2022-02-13 12:02:28 +08:00
    现在还是不支持 format selection... 等了多少年了, 一点放开口子的趋势都不给, 给个 --lines 参数也行

    有时候我要给别人代码提 commit, 我不能因为改一行代码格式化一两万行别人代码啊. 至于说拉出来单独格式化或者用 darker... 算了
    yucongo
        5
    yucongo  
       2022-02-13 23:57:17 +08:00
    # fmt:off
    ...
    # fmt: on
    可以临时关掉 black 。以前 black 和 pylint 在多行定义函数时有冲突我常用这个。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1003 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 22:32 · PVG 06:32 · LAX 15:32 · JFK 18:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.