-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CodeStyle][black] use black instead of yapf #46014
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
This comment was marked as outdated.
This comment was marked as outdated.
发现了 yapf 若干问题,这里再次尝试评估下收益 |
db3b275
to
09e4875
Compare
很抱歉,经过我们的反复讨论,你的PR暂未达到合入标准,请阅读飞桨原生算子开发规范,你可以重新提交新的PR,我们先将此PR关闭,感谢你的贡献。 |
在解决 trailing-whitespace 和 tabs 后的新统计(全部错误码,之前统计是默认配置,有 11 个错误码没统计): 全量统计:
排除 fluid(但包含 fluid/tests):
注:标 这次 black 对 E 和 W 的修复程度媲美 autopep8 了,估计是因为 #46410 移除了部分 disable 后 black 在相关文件里进行了格式化的效果 仅有 4 个 CI 未通过(无单测相关,单测均已通过) |
0efc53e
to
ae81d8d
Compare
black 替换 yapf 的优势1. Github 使用情况根据 #46014 (comment) ,black 的 stars 数、使用量、速度都远超 yapf。
2. 业内调研pytorch 的 python 工具为: 3. Error 数量和项目大大减少根据 #46014 (comment) ,整理:在解决 trailing-whitespace 和 tabs 后的新统计(除 E501 的全部错误码,排除 fluid,但包含 fluid/tests):
大大减少的错误码可以让开发者专注于编写代码逻辑,而不是浪费时间在调整代码格式上 4. 生态更好有很多工具对 black 支持/兼容性更好,比如 isort 专门有个 profile 就是针对 black 的,可以保证与 black 没有冲突,而 yapf 则很难与 isort 一起工作(见 #46475 (comment) ),以及 docstring、rst 文档示例代码格式化工具 https://github.com/asottile/blacken-docs 也是集成了 black black 替换 yapf 的不足(代码风格)
black 替换 yapf 的可行性操作
|
ae81d8d
to
180f8b0
Compare
180f8b0
to
bd10211
Compare
[tool.black] | ||
exclude = "build" | ||
line-length = 80 | ||
skip-string-normalization = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以加一下skip-string-normalization
参数的说明
084a66a
to
ba941ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
release/2.4 的仅配置修改 PR 已提交:#47146 |
794e895
to
9ed57dc
Compare
afddd50
to
da46870
Compare
PR types
Others
PR changes
Others
Describe
Use black as the new code formatting tool and format existing code.
本 PR 做了如下修改:
'
包裹,black 默认是强制使用"
包裹字符串的,后来做出了妥协添加了这一参数,这里也是为了尽可能减少代码变动而添加的参数(如不添加则 30 万行 changes、添加后为 24 万行)