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][C403] Unnecessary list comprehension (rewrite as a set comprehension) #51968

Merged
merged 1 commit into from
Mar 23, 2023

Conversation

enkilee
Copy link
Contributor

@enkilee enkilee commented Mar 22, 2023

PR types

Others

PR changes

Others

Describe

Unnecessary list comprehension (rewrite as a set comprehension)
According to https://beta.ruff.rs/docs/rules/unnecessary-generator-set/ and https://pypi.org/project/flake8-comprehensions/
C403 : Unnecessary list comprehension - rewrite as a set comprehension.

So we can rewrite set([f(x) for x in foo]) as {f(x) for x in foo}

Timing use:

>>>from timeit import timeit
>>>time(set([i for i in range(100)]))
CPU times: user 12 µs, sys: 3 µs, total: 15 µs
Wall time: 18.6 µs
>>>time({i for i in range(100)})
CPU times: user 10 µs, sys: 0 ns, total: 10 µs
Wall time: 14.3 µs

Changed 19 files, 24 places, and no semantic or syntax error. The conclusions are as follows:
using rule:✅
auto fix:✅

command as follow:

# install ruff 0.0.254
pip install ruff==0.0.254
# using command to auto fix:
ruff --select C403 . --fix

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTM

配置记得在之后 PR 里一并修改

@paddle-bot paddle-bot bot added the contributor External developers label Mar 22, 2023
@luotao1 luotao1 merged commit ca7394c into PaddlePaddle:develop Mar 23, 2023
@enkilee enkilee deleted the codestyle_c403 branch April 2, 2023 10:23
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