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

New checks: Use list / dict literal syntax #4365

Closed
nickdrozd opened this issue Apr 16, 2021 · 0 comments · Fixed by #4769
Closed

New checks: Use list / dict literal syntax #4365

nickdrozd opened this issue Apr 16, 2021 · 0 comments · Fixed by #4769
Labels
Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors
Milestone

Comments

@nickdrozd
Copy link
Collaborator

Sometimes I see stuff like this:

x = list()
y = dict()

These would clearer as:

x = []
y = {}

I would like to see two new checks, use-list-literal and use-dict-literal, or something like that.

@Pierre-Sassoulas Pierre-Sassoulas added Good first issue Friendly and approachable by new contributors Enhancement ✨ Improvement to a component Help wanted 🙏 Outside help would be appreciated, good for new contributors labels Apr 16, 2021
DanielNoord added a commit to DanielNoord/pylint that referenced this issue Jul 29, 2021
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
DanielNoord added a commit to DanielNoord/pylint that referenced this issue Jul 29, 2021
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
DanielNoord added a commit to DanielNoord/pylint that referenced this issue Jul 29, 2021
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
Pierre-Sassoulas added a commit that referenced this issue Jul 29, 2021
* Add ``use-list-literal`` and ``use-dict-literal``
This adds two checks for when empty lists and dicts are created
using a function call instead of their literals.
This closes #4365

* Conform code to use-list-literal, use-dict-literal
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.

* Conform test to use-list-literal, use-dict-literal
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.

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
@cdce8p cdce8p added this to the 2.10.0 milestone Aug 2, 2021
stanislavlevin added a commit to stanislavlevin/freeipa-healthcheck that referenced this issue Feb 15, 2022
Pylint 2.10 introduced new checker use-dict-literal:
> Added use-dict-literal: Emitted when dict() is called with no
  arguments instead of using {}

https://pylint.pycqa.org/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-10-0
pylint-dev/pylint#4365

Fixes: freeipa#244
Signed-off-by: Stanislav Levin <slev@altlinux.org>
stanislavlevin added a commit to stanislavlevin/freeipa-healthcheck that referenced this issue Feb 15, 2022
Pylint 2.10 introduced new checker use-list-literal:
> Added use-list-literal: Emitted when list() is called with no
  arguments instead of using []

https://pylint.pycqa.org/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-10-0
pylint-dev/pylint#4365

Fixes: freeipa#244
Signed-off-by: Stanislav Levin <slev@altlinux.org>
stanislavlevin added a commit to stanislavlevin/fc-admin that referenced this issue Feb 17, 2022
Pylint 2.10 introduced new checker:
> Emitted when using list() to create an empty list instead of the
  literal []. The literal is faster as it avoids an additional function
  call.

See pylint-dev/pylint#4365

Fixes: fleet-commander#279
Signed-off-by: Stanislav Levin <slev@altlinux.org>
stanislavlevin added a commit to stanislavlevin/fc-admin that referenced this issue Feb 17, 2022
Pylint 2.10 introduced new checker:
> Emitted when using dict() to create an empty dictionary instead of the
  literal {}. The literal is faster as it avoids an additional function
  call.

See pylint-dev/pylint#4365

Fixes: fleet-commander#279
Signed-off-by: Stanislav Levin <slev@altlinux.org>
stanislavlevin added a commit to stanislavlevin/fc-admin that referenced this issue Feb 17, 2022
Pylint 2.10 introduced new checker:
> Emitted when using list() to create an empty list instead of the
  literal []. The literal is faster as it avoids an additional function
  call.

See pylint-dev/pylint#4365

Fixes: fleet-commander#279
Signed-off-by: Stanislav Levin <slev@altlinux.org>
stanislavlevin added a commit to stanislavlevin/fc-admin that referenced this issue Feb 17, 2022
Pylint 2.10 introduced new checker:
> Emitted when using dict() to create an empty dictionary instead of the
  literal {}. The literal is faster as it avoids an additional function
  call.

See pylint-dev/pylint#4365

Fixes: fleet-commander#279
Signed-off-by: Stanislav Levin <slev@altlinux.org>
olivergs pushed a commit to fleet-commander/fc-admin that referenced this issue Mar 3, 2022
Pylint 2.10 introduced new checker:
> Emitted when using list() to create an empty list instead of the
  literal []. The literal is faster as it avoids an additional function
  call.

See pylint-dev/pylint#4365

Fixes: #279
Signed-off-by: Stanislav Levin <slev@altlinux.org>
olivergs pushed a commit to fleet-commander/fc-admin that referenced this issue Mar 3, 2022
Pylint 2.10 introduced new checker:
> Emitted when using dict() to create an empty dictionary instead of the
  literal {}. The literal is faster as it avoids an additional function
  call.

See pylint-dev/pylint#4365

Fixes: #279
Signed-off-by: Stanislav Levin <slev@altlinux.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants