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

[Don't merge][CodeStyle][pyupgrade] automatically rewrite code with ruff #50477

Closed
wants to merge 2 commits into from

Conversation

SigureMo
Copy link
Member

@SigureMo SigureMo commented Feb 13, 2023

PR types

Others

PR changes

Others

Describe

#48140,只不过使用的是 ruff,先测试下效果

相关讨论见 #50458 (comment)

本 PR 仅用于测试 ruff 实现的 pyupgrade rules 是否有问题,不会直接合入,最终会逐条 rule 引入,以便 review

关于 pyupgrade 错误码统计(含 UPC40[*] 为可自动修复,这里全部错误码均可自动修复):

paddle ❯ ruff . --statistics       
  19    C400    [*] Unnecessary generator (rewrite as a `list` comprehension)
   5    C401    [*] Unnecessary generator (rewrite as a `set` comprehension)
   4    C402    [*] Unnecessary generator (rewrite as a `dict` comprehension)
  22    C403    [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension)
   2    C404    [*] Unnecessary `list` comprehension (rewrite as a `dict` comprehension)
 176    C405    [*] Unnecessary `list` literal (rewrite as a `set` literal)
 347    C408    [*] Unnecessary `tuple` call (rewrite as a literal)
   3    C409    [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)
  13    UP004   [*] Class `Event` inherits from `object`
   6    UP005   [*] `assertEquals` is deprecated, use `assertEqual`
   1    UP006   [*] Use `list` instead of `List` for type annotations
  50    UP008   [*] Use `super()` instead of `super(__class__, self)`
  16    UP009   [*] UTF-8 encoding declaration is unnecessary
   2    UP010   [*] Unnecessary `__future__` import `print_function` for target Python version
   2    UP012   [*] Unnecessary call to `encode` as UTF-8
 137    UP015   [*] Unnecessary open mode parameters
  51    UP018   [*] Unnecessary call to `str`
   9    UP024   [*] Replace aliased errors with `OSError`
  10    UP027   [*] Replace unpacked list comprehension with a generator expression
  10    UP028   [*] Replace `yield` over `for` loop with `yield from`
 278    UP030   [*] Use implicit references for positional format fields
 136    UP031   [*] Use format specifiers instead of percent format
1315    UP032   [*] Use f-string instead of `format` call
 216    UP034   [*] Avoid extraneous parentheses
   1    UP036   [*] Version block is outdated for minimum Python version

修改

.pre-commit-config.yaml

-   repo: https://github.com/charliermarsh/ruff-pre-commit
    rev: v0.0.247
    hooks:
    -   id: ruff
        args: [--fix, --exit-non-zero-on-fix, --no-cache]

pyproject.toml

[tool.ruff]
exclude = [
    "./build",
    "./python/paddle/fluid/[!t]**",
    "./python/paddle/fluid/tra**",
    "./python/paddle/utils/gast/**",
    "./python/paddle/fluid/tests/unittests/npu/**",
    "./python/paddle/fluid/tests/unittests/mlu/**",
]
select = ["UP", "C40"]
ignore = ["UP015", "UP030"]
target-version = "py37"

[tool.ruff.per-file-ignores]
"setup.py" = ["UP036"]

@paddle-bot-old paddle-bot-old bot added the contributor External developers label Feb 14, 2023
@luotao1 luotao1 self-assigned this Feb 14, 2023
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.

2 participants