-
-
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
Add new checkers use-list-literal
and use-dict-literal
#4769
Add new checkers use-list-literal
and use-dict-literal
#4769
Conversation
This adds two checks for when empty lists and dicts are created using a function call instead of their literals. This closes pylint-dev#4365
With addition of the use-list-literal and use-dict-literal checkers some code had to be updated. As there is a real performance difference, the literal is preferred when it is as clear as using the function call.
With addition of the use-list-literal and use-dict-literal checkers some code had to be updated. As there is a real performance difference, the literal is preferred when it is as clear as using the function call. For some tests ignoring the checker seemed better for clarity of the test.
c8114e5
to
4cdd984
Compare
Little update, my IDE's automatic linter is a bit too aggressive. Should be good now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this one!
# pylint: disable=missing-docstring, invalid-name | ||
|
||
x = dict() # [use-dict-literal] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename the test files?
use_dict_literal -> use_literal_dict
use_list_literal -> use_literal_list
That will make testing them a bit easier, as you then can do pytest tests/test_functional -k use_literal
to just test these two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe -k literal
is close enough ? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only renamed the test files. Should I have changed the message code as well? To keep it in line with document names? Or is this fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cdce8p Just making sure you didn't miss this comment. No changes needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment was just about the test file names. So everything is fine with it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to talk about safe_infer
too but I think @cdce8p made a very nice point performance wise regarding the possibility to not have to infer every Call node.
# pylint: disable=missing-docstring, invalid-name | ||
|
||
x = dict() # [use-dict-literal] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe -k literal
is close enough ? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just nitpicking at this point 😄
Co-authored-by: Marc Mueller <[email protected]>
Co-authored-by: Marc Mueller <[email protected]>
Isn't that the whole point of |
@DanielNoord It sometimes certainly feels that way (: |
doc/whatsnew/<current release.rst>
.Type of Changes
Description
Add
use-list-literal
anduse-dict-literal
checkers as described in #4365.This adds two checks for when empty lists and dicts are created using a function call instead of their literals.
Tests and
pylint
code have been updated as well to conform to or ignore the new checker.This closes #4365