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

Add new checkers use-list-literal and use-dict-literal #4769

Merged
merged 7 commits into from Jul 29, 2021

Conversation

DanielNoord
Copy link
Collaborator

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature, or an important bug fix, add a What's New entry in
    doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Type of Changes

Type
✨ New feature

Description

Add use-list-literal and use-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

@coveralls
Copy link

coveralls commented Jul 29, 2021

Coverage Status

Coverage increased (+0.005%) to 92.257% when pulling 947b8ef on DanielNoord:list-dict-literal into ca3bc53 on PyCQA:main.

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.
@DanielNoord
Copy link
Collaborator Author

Little update, my IDE's automatic linter is a bit too aggressive.

Should be good now!

@cdce8p cdce8p self-requested a review July 29, 2021 11:59
Copy link
Member

@cdce8p cdce8p left a 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/checkers/refactoring/refactoring_checker.py Outdated Show resolved Hide resolved
pylint/checkers/refactoring/refactoring_checker.py Outdated Show resolved Hide resolved
pylint/checkers/refactoring/refactoring_checker.py Outdated Show resolved Hide resolved
Comment on lines 1 to 3
# pylint: disable=missing-docstring, invalid-name

x = dict() # [use-dict-literal]
Copy link
Member

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.

Copy link
Member

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 ? :)

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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?

Copy link
Member

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

@cdce8p cdce8p added the Enhancement ✨ Improvement to a component label Jul 29, 2021
@cdce8p cdce8p added this to the 2.10.0 milestone Jul 29, 2021
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a 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.

Comment on lines 1 to 3
# pylint: disable=missing-docstring, invalid-name

x = dict() # [use-dict-literal]
Copy link
Member

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 ? :)

Copy link
Member

@cdce8p cdce8p left a 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 😄

pylint/checkers/refactoring/refactoring_checker.py Outdated Show resolved Hide resolved
ChangeLog Outdated Show resolved Hide resolved
DanielNoord and others added 2 commits July 29, 2021 22:05
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
@DanielNoord
Copy link
Collaborator Author

Just nitpicking at this point 😄

Isn't that the whole point of pylint? 😉

@cdce8p
Copy link
Member

cdce8p commented Jul 29, 2021

Just nitpicking at this point 😄

Isn't that the whole point of pylint? 😉

@DanielNoord It sometimes certainly feels that way (:
Thanks again 🐬

@Pierre-Sassoulas Pierre-Sassoulas merged commit 23412dc into pylint-dev:main Jul 29, 2021
@DanielNoord DanielNoord deleted the list-dict-literal branch July 29, 2021 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New checks: Use list / dict literal syntax
4 participants