-
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][isort] introducing isort
(part1)
#46475
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
你的PR提交成功,感谢你对开源项目的贡献! |
SigureMo
changed the title
[CodeStyle][E401] use isort sort imports
[Don't merge][CodeStyle][E401] use isort sort imports
Sep 25, 2022
This comment was marked as outdated.
This comment was marked as outdated.
SigureMo
force-pushed
the
isort/fix/all
branch
from
October 24, 2022 09:23
bf161ac
to
ce50977
Compare
SigureMo
changed the title
[Don't merge][CodeStyle][E401] use isort sort imports
[Don't merge][CodeStyle] use isort sort imports
Oct 24, 2022
SigureMo
force-pushed
the
isort/fix/all
branch
from
October 24, 2022 16:29
ce50977
to
526c02a
Compare
SigureMo
changed the title
[Don't merge][CodeStyle] use isort sort imports
[Don't merge][CodeStyle] introducing Oct 27, 2022
isort
and using it to sort imports
SigureMo
force-pushed
the
isort/fix/all
branch
from
October 27, 2022 14:14
526c02a
to
09cdd87
Compare
SigureMo
changed the title
[Don't merge][CodeStyle] introducing
[CodeStyle] introducing Oct 28, 2022
isort
and using it to sort importsisort
and using it to sort imports (part1)
luotao1
previously approved these changes
Oct 28, 2022
SigureMo
changed the title
[CodeStyle] introducing
[CodeStyle][isort] introducing Oct 28, 2022
isort
and using it to sort imports (part1)isort
and using it to sort imports (part1)
raindrops2sea
previously approved these changes
Nov 1, 2022
SigureMo
force-pushed
the
isort/fix/all
branch
3 times, most recently
from
November 13, 2022 08:29
b9135f2
to
5b2c6d5
Compare
请解决下冲突 |
SigureMo
force-pushed
the
isort/fix/all
branch
2 times, most recently
from
November 24, 2022 06:15
109ae95
to
0d6840a
Compare
SigureMo
changed the title
[CodeStyle][isort] introducing
[CodeStyle][isort] introducing Nov 24, 2022
isort
and using it to sort imports (part1)isort
(part1)
SigureMo
force-pushed
the
isort/fix/all
branch
from
November 24, 2022 10:05
0d6840a
to
124aacf
Compare
SigureMo
force-pushed
the
isort/fix/all
branch
from
November 24, 2022 12:44
124aacf
to
5347c25
Compare
@luotao1 现在已经没有冲突了,是否可以准备合入这个 PR 了? |
luotao1
approved these changes
Nov 25, 2022
This was referenced Nov 25, 2022
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Others
PR changes
Others
Describe
RFC: Python 引入 import 区域自动重排工具 isort 方案
引入工具 isort 以及对部分文件进行格式化
isort 是一个对文件中 imports 部分进行重排的工具,会依照 PEP 8 - imports 规范以下规则对 imports 进行重排
可以极大改善 imports 部分的代码风格,使得开发人员更容易了解模块之间的依赖关系,且能够自动去除 imports 部分重复的导入
isort 同时可以稍微消除一部分 flake8 错误码1,如完全消除 E401(multiple imports on one line)(存量 9 -> 0),因为可以去重所以可以消除部分 F811(redefinition of unused
name
from lineN
)(存量 123 -> 46),但这只是引入 isort 额外的收获,其主要作用还是改善 imports 部分的代码风格(虽然这不在 flake8 错误码里,但是 PEP 8 中描述的)其他社区使用 isort 的例子:
.isort.cfg
shell/format.sh
实施步骤:
pyproject.toml
配置添加类似 flake8 的 F401 引入,先在配置中 ignore 一部分,但由于 isort 只是对 import 排序,大多数情况不会有影响(少数的比如一个 import 中修改全局状态,后一个 import 依赖于此全局状态可能会有影响),因此可相对于 F401 目录的划分粒度大一些(利用 10 个以内 PR 完成,实际应该会更少些)
isort .
由于配置里 ignore 了部分路径,因此只会格式化一部分路径,之后每个 PR 解开一部分路径之后
isort .
即可,针对有问题的先 ignore 掉在之后 PR 里解决Footnotes
[CodeStyle] Flake8 tracking issue #46039 ↩