Closed
Description
项目说明
用于跟踪 Call-for-Contributions: Flake8 引入计划 及相关 CodeStyle 升级各个任务的计划和进度
部分针对任意文本的代码风格全量修复需要同样为如文档(.md
、.rst
)、C++ 相关文件(.cc
、.c
、.h
、.cu
、.cpp
、.cmake
、CMakeLists.txt
)一并修复
项目初始状态
Flake8 默认启用的三个工具(pycodestyle、pyflakes、mccabe)共包含了一共 132 个子项。Paddle 中存在问题的子项共 64 个。
- 错误码参考:
- 根据错误码的子项统计说明见:[CodeStyle] init flake8 configs #45943 (comment) [CodeStyle] add pre-commit hook
remove-tabs
for python files #46290 (comment) - 推进方式:采用在
.flake8
配置文件中 ignore 现存的错误码来推进,修复一类错误就去掉一个错误码
Flake8 阶段性成果总结 (54/62)
序号 | 子任务和完成时间 | 对应错误码和出现次数 | 相关 PR | 修复行数 | 增量拦截手段 pre-commit hook | 作者 |
---|---|---|---|---|---|---|
1 | fail to compile a file into an AST (2022/08/23) | E999(1) | #45287 | 1 | flake8 | SigureMo |
2-3 | trailing whitespace (2022/09/19) | W291(4146) W293(1696) |
#45937, #46042, #45990, #46006, #46080, #44474, #46067, #46081 | C++ (602) Python (6000) 文档(67) hook/yaml(63) |
trailing-whitespace (自动修复)+ flake8 |
SigureMo, betterpig |
4-5 | Tabs (2022/09/27) | E101(587) W191(587) |
#46288, #46357, #46309, #46236, #46290, #46232 | C++ (34) Python (246) |
remove-tabs (自动修复)+ flake8 |
SigureMo |
6 | import module from line N shadowed by loop variable (2022/10/10) | F402(1) | #46698, #46699 | 1 | flake8 | caolonghao |
7 | .has_key() is deprecated, use ‘in’ (2022/10/10) | W601(3) | #46702, #46703 | 3 | flake8 | caolonghao |
8 | dictionary key name repeated with different values (2022/10/10) |
F601(7) | #46719, #46720 | 14 | flake8 | caolonghao |
9 | test for membership should be ‘not in’ (2022/10/11) | E713(22) | #46734, #46855 | 22 | flake8 | caolonghao |
10 | test for object identity should be ‘is not’ (2022/10/11) | E714(4) | #46741 | 4 | flake8 | caolonghao |
11 | assertion test is a tuple, which is always True (2022/10/11) |
F631(2) | #46739 | 14 | flake8 | gglin001, caolonghao |
12 | use ==/!= to compare str , bytes , and int literals (2022/10/11) |
F632(18) | #46708, #46856 | 18 | flake8 | caolonghao |
13 | .format(...) missing argument (2022/10/11) |
F524(1) | #46745, #46854 | 1 | flake8 | caolonghao |
14 | f-string without any placeholders (2022/10/11) | F541(33) | #46700 | 36 | flake8 | caolonghao |
15 | expected 1 blank line before a nested definition (2022/10/11) | E306(1) | #46895, #46897 | 1 | flake8 | SigureMo |
16 | Module imported but unused (2022/10/12) | F401(6750) | cattidea#4 (33个PR) #47455 |
4891 | autoflake(自动修复) + flake8 |
SigureMo, Yulv-git, Aurelius84 |
17 | ‘from module import *’ used; unable to detect undefined names (2022/10/19) | F403(57) | #46946, #46947 | 51 | flake8 | SigureMo |
18 | invalid escape sequence ‘x’ (2022/10/20) | W605(172) | #46752, #46753 | 77 | flake8 | caolonghao |
19-44 | 常见格式问题(black 可解决)(2022/10/24) | E121(8) E122(81) E123(12) E125(168) E126(723) E127(140) E128(207) E129(9) E131(45) E201(29) E202(11) E225(61) E226(93) E228(3) E241(2) E251(109) E261(11) E271(4) E272(1) E301(7) E302(3) E303(7) E305(2) E502(400) E701(108) W504(949) |
#46014, #47266, #47268, #47146 | - | black(自动修复) + flake8 |
SigureMo |
45 | .format(...) unused named arguments (2022/10/24) |
F522(1) | #46743, #47287 | 2 | flake8 | caolonghao |
46 | missing whitespace after ‘,’, ‘;’, or ‘:’ (2022/10/25) | E231(3) | #47297, #47298 | 5 | flake8 | SigureMo |
47 | comparison to None should be ‘if cond is None:’ (2022/11/01) | E711(168) | #47452, #47465 | 357 | flake8 | SigureMo |
48 | comparison to True should be ‘if cond is True:’ or ‘if cond:’ (2022/11/01) | E712(331) | #47464 | 403 | flake8 | SigureMo |
49-50 | inline/block comment should start with ‘# ‘ (2022/11/07) | E262(17) E265(29) |
#47687 | 50 | flake8 | SigureMo |
51 | too many leading ‘#’ for block comment (2022/11/09) | E266(106) | #47772, #47773 | 159 | flake8 | caolonghao |
52 | undefined name name (2022/11/15) |
F821(75) | #47756, #47869, #47899, #47968 | 223 | flake8 | SigureMo |
53 | multiple imports on one line (2022/12/05) | E401(8) | #48538 | 94 | flake8 | SigureMo |
54 | redefinition of unused name from line N (2022/12/08) |
F811(123) | #48745 | 65 | flake8 | SigureMo |
- | module level import not at top of file (TODO) | E402(1309) | #50458 暂时 hold | @SigureMo | ||
- | line too long (82 > 79 characters) (TODO) | E501(16517) | 同上 | |||
- | do not compare types, use ‘isinstance()’ (TODO) | E721(8) | 同上 | |||
- | do not use bare except, specify exception instead (TODO) | E722(151) | 同上 | |||
- | do not assign a lambda expression, use a def (TODO) | E731(64) | 同上 | |||
- | do not use variables named ‘l’, ‘O’, or ‘I’ (TODO) | E741(144) | 同上 | |||
- | name may be undefined, or defined from star imports: module (TODO) | F405(212) | 同上 | |||
- | local variable name is assigned to but never used (TODO) |
F841(2124) | 同上 |
Note
- 这里仅统计已经完成的任务,具体各个任务的计划和进度见下方评论区。
- 错误码出现次数和最终修复行数会有差异:一方面两者统计时间不一样,另一方面错误码统计方式是出现次数,有一行同一个错误码出现多次的情况,也有一处错误码占据多行的情况。
- 统计行数为 diff 中增加行数与减少行数中较大值,因为部分任务需要删除内容,而部分则需要增加内容,较大值更能反映实际修改行数
其他成果总结
子任务和完成时间 | 相关 PR |
---|---|
修复 cpplint hook 在 CI 不生效的问题(2022/09/19) | #46136 |
修复 Remove-CRLF / Detect Private Key hook 在 CI 不生效的问题(2022/09/20) | #46154 #46155 #46156 |
对错误使用 yapf: disable 的文件进行调整(2022/09/22) |
#46410 |
引入 isort 工具(2022/12/01) | #46475, #48390, #48401, #48402, #48404, #48522 |
Metadata
Labels
Type
Projects
Status
Done