-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Prefer dict literal over dict
constructor
#7690
Comments
I just came across this new check (from running latest in Astroid). It seems awfully opinionated to me. Is it the official stance of Pylint that this syntax is bad? Is it old or deprecated or something? The official documentation doesn't say much about it, just that "when the keys are simple strings, it is sometimes easier to specify pairs using keyword arguments". So one reason you might want it is if you don't want extra strings floating around. It's certainly not a widely used way to make dictionaries, but I don't see why it should be recommended against. Is it really slower? |
https://github.com/PyCQA/pylint/blob/main/doc/data/messages/u/use-dict-literal/details.rst If this was a feature where the devs decided that one version looks better than the other and style was the only consideration, I'd agree that it is opinionated. But this was not the case here at all. Literals are faster. And faster is better when there's so little difference in style (my personal opinion). It would even make sense to expand this rule to sets and lists (maybe this is already working or in the works). |
Okay, I'm agreed then on the other constructors as well. |
Current problem
Constructing
dict
s using the constructor should be avoided. It has no advantages and may be a bit slower.Invalid code
Valid code
Desired solution
Create a message that finds and highlights invalid code from above. Maybe as an extension of
R1735 use-dict-literal
.Additional context
No response
The text was updated successfully, but these errors were encountered: