-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
New checks: Use literals instead of calling the constructor #6542
Comments
Thank you for opening the issue. It definitely make sense to extends the check. I think we can keep the |
@Pierre-Sassoulas I'm working on a version of this, but I'm not very familiar with |
You should clone the repository and install pylint in a virtualenv with
I think you can do some check on the call's args/kwargs. It should return a list of nodes : https://pylint.pycqa.org/projects/astroid/en/latest/api/astroid.nodes.html#astroid.nodes.Call.args |
@Pierre-Sassoulas Thank you! I got the code to work and the tests to run, and made a PR. |
Current problem
Literals should be prioritized over calling their respective constructors because it is clearer.
Demonstrations of new checks:
Should be (Correct code):
For both of the above pylint gives a rating of 10.0/10.0.
Desired solution
I propose a couple new checks, or they could all be merged into a
use-literal
instead.The list example and dict example should be part of
use-list-literal
anduse-dict-literal
, and the set and tuple examples could beuse-set-literal
anduse-tuple-literal
. I can see some argument against the tuple literal, as it could be confusing in some parentheses-dense situations, but the other checks would almost always (if not always) make things clearer.Additional context
Similar to issue #4365 but for
set
,tuple
, and more complicated expressions.The text was updated successfully, but these errors were encountered: