Skip to content
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][ruff] update ruff v0.0.287 and fix F401 #57124

Closed
wants to merge 4 commits into from

Conversation

gouzil
Copy link
Member

@gouzil gouzil commented Sep 8, 2023

PR types

Others

PR changes

Others

Description

第一阶段

存量统计

升级ruff 至 v0.0.287 并新增检查

ruff --select UP . --statistics
873	UP032	[*] Use f-string instead of `format` call
172	UP015	[*] Unnecessary open mode parameters
 43	UP018	[*] Unnecessary `bool` call (rewrite as a literal)
  7	UP028	[*] Replace `yield` over `for` loop with `yield from`
  1	UP004	[*] Class `Event` inherits from `object`
ruff --select PL . --statistics
2506	PLR2004	[ ] Magic value used in comparison, consider replacing -0.5 with a constant variable
1662	PLR0913	[ ] Too many arguments to function call (10 > 5)
 565	PLR0912	[ ] Too many branches (13 > 12)
 539	PLR0915	[ ] Too many statements (100 > 50)
 366	PLW2901	[ ] Outer `for` loop variable `i` overwritten by inner `for` loop target
 281	PLR1714	[ ] Consider merging multiple comparisons. Use a `set` if the elements are hashable.
 254	PLR5501	[ ] Use `elif` instead of `else` then `if`, to reduce indentation
 204	PLW0603	[ ] Using the global statement to update `CATEGORIES_DICT` is discouraged
 140	PLR1711	[*] Useless `return` statement at end of function
 105	PLW0602	[ ] Using global for `API_DEV_SPEC_FN` but no assignment is done
  51	PLR1701	[*] Merge `isinstance` calls: `isinstance(ckpt, (Variable, str))`
  49	PLR0911	[ ] Too many return statements (10 > 6)
  26	PLW1508	[ ] Invalid type for environment variable default; expected `str` or `None`
  23	PLW0127	[ ] Self-assignment of variable `_startup`
  14	PLR0124	[ ] Name compared with itself, consider replacing `H != H`
  13	PLC0208	[ ] Use a sequence type instead of a `set` when iterating over values
   6	PLW1510	[ ] `subprocess.run` without explicit `check` argument
   5	PLR0133	[ ] Two constants compared in a comparison, consider replacing `10 > 5`
   5	PLW0129	[ ] Asserting on a non-empty string literal will always pass
   3	PLW1509	[ ] `preexec_fn` argument is unsafe when using threads
   2	PLR1722	[*] Use `sys.exit()` instead of `quit`
   2	PLW0120	[ ] `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it
   2	PLW3301	[*] Nested `min` calls can be flattened
ruff --select B . --statistics
863	B007	[*] Loop control variable `alignment` not used within loop body
233	B006	[*] Do not use mutable data structures for argument defaults
177	B028	[ ] No explicit `stacklevel` keyword argument found
129	B023	[ ] Function definition does not bind loop variable `K`
 72	B904	[ ] Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
 23	B008	[ ] Do not perform function call `DistributedStrategy` in argument defaults
 15	B017	[ ] `assertRaises(BaseException)` should be considered evil
 10	B026	[ ] Star-arg unpacking after a keyword argument is strongly discouraged
  8	B005	[ ] Using `.strip()` with multi-character strings is misleading the reader
  3	B027	[ ] `AlgorithmBase.collect_model_info` is an empty method in an abstract base class, but has no abstract decorator
  3	B033	[ ] Sets should not contain duplicate item `"multiply_grad"`
  1	B024	[ ] `FLClientBase` is an abstract base class, but it has no abstract methods

tracking issue

序号 错误码 存量 认领人 完成 PR
1 UP032 983
2 B007 863
3 UP015 175
4 PLR1711 140
5 NPY003 64
6 PLR1701 51
7 UP018 43
8 UP031 33
9 C408 28
10 UP030 23
11 F403 11
12 UP028 11
13 F522 5
14 F811 4
15 C403 3
16 UP034 3
17 C405 2
18 C417 2
19 PLR1722 2
20 PLW3301 2
21 F821 1
22 C411 1
23 C416 1
24 UP004 1

B006 需要单独确认是否添加B006 mutable-argument-default

Note

在新增检查的同时需要同时删除 exclude 中的 ./python/paddle/base/** 选项
做完后需在 ignore 中删除序号, 或者在 select 中删除注释

第二阶段

删除 exclude 中的 ./python/paddle/base/** 选项, 并修复已存在的所有检查

序号 错误码 存量 认领人 完成 PR
1 F401 163
2 B017 15
3 B010 4
4 B011 2
5 PLR0402 2
6 B004 1
7 B009 1
8 B016 1
9 B019 1
10 PLC0414 1

相关文档

常用命令

# 安装 ruff v0.0.287
pip install ruff==0.0.287
# 本 rule 自动修复方案不合适,因此仅仅跑一下(不加 `--fix`),之后手动修复
ruff --select NPY003 .
# 手动修复中...

@paddle-bot
Copy link

paddle-bot bot commented Sep 8, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Sep 8, 2023
Comment on lines +93 to +110
"F403", # Open Later
"F522", # Open Later
"F811", # Open Later
"F821", # Open Later
"C408", # Open Later
"C403", # Open Later
"C405", # Open Later
"C417", # Open Later
"C411", # Open Later
"C416", # Open Later
"UP032", # Open Later
"UP015", # Open Later
"UP018", # Open Later
"UP031", # Open Later
"UP030", # Open Later
"UP028", # Open Later
"UP034", # Open Later
"UP004", # Open Later
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全局 ignore?为什么全局 ignore?这是有风险的

Comment on lines +49 to +50
# "B006", # To be confirmed
# "B007",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这俩不都是你调研的不适合引入的么 #51729

Comment on lines +75 to +78
# "PLR1701",
# "PLR1711",
# "PLR1722",
# "PLW3301",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PLR1701、PLR1722 应该是修复了但是忘记修改配置

PLR1711、PLW3301 是最近新增的是么

@gouzil gouzil marked this pull request as draft September 9, 2023 09:32
@luotao1 luotao1 self-assigned this Sep 11, 2023
@gouzil gouzil closed this Sep 15, 2023
@gouzil gouzil deleted the update_ruff branch December 27, 2023 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants