Skip to content

RUFF C408 rule (unnecessary-collection-call) #6316

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

Closed
wants to merge 4 commits into from

Conversation

bigcat88
Copy link
Contributor

@bigcat88 bigcat88 commented Jan 2, 2025

This rule checks for unnecessary dict(), list() or tuple() calls that can be rewritten as empty literals.

Why is this bad?

It's unnecessary to call, e.g., dict() as opposed to using an empty literal ({}). The former is slower because the name dict must be looked up in the global scope in case it has been rebound.

Examples:

dict()
dict(a=1, b=2)
list()
tuple()

Use instead:

{}
{"a": 1, "b": 2}
[]
()

Ruff's docs link

huchenlei
huchenlei previously approved these changes Jan 2, 2025
webfiltered
webfiltered previously approved these changes Jan 10, 2025
@bigcat88
Copy link
Contributor Author

@comfyanonymous should I open a PRs for multiple-starts-ends-with (PIE810) or/and unnecessary-range-start (PIE808) rules, after merge of this one?

They are both will be small, without many edits.

@bigcat88
Copy link
Contributor Author

bigcat88 commented Jan 19, 2025

just a friendly note: This PR is rebased and ready. If it is not needed, please close it.

Copy link

@wibur0620 wibur0620 left a comment

Choose a reason for hiding this comment

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

👌

@bigcat88
Copy link
Contributor Author

In total, there are more than 100 PRs hanging in the repository, so I close mine.

@bigcat88 bigcat88 closed this Feb 15, 2025
@bigcat88 bigcat88 deleted the ruff/C408 branch February 15, 2025 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants