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

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
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
ruff.toml Outdated Show resolved Hide resolved
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.

2 participants