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

More descriptive message for use-implicit-booleaness-not-comparison #7725

Conversation

Pierre-Sassoulas
Copy link
Member

Type of Changes

Type
βœ“ πŸ”¨ Refactoring
βœ“ πŸ“œ Docs

Description

Follow-up to #7723 in order to make #6870 more reviewable.

@Pierre-Sassoulas Pierre-Sassoulas added Documentation πŸ“— Skip news πŸ”‡ This change does not require a changelog entry labels Nov 7, 2022
@Pierre-Sassoulas Pierre-Sassoulas changed the title More actionnable message for use-implicit-booleaness-not-comparison More descriptive message for use-implicit-booleaness-not-comparison Nov 7, 2022
@coveralls
Copy link

coveralls commented Nov 7, 2022

Pull Request Test Coverage Report for Build 3408761029

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.0003%) to 95.382%

Totals Coverage Status
Change from base Build 3408490230: -0.0003%
Covered Lines: 17246
Relevant Lines: 18081

πŸ’› - Coveralls

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the more-actionnable-message-for-use-implicit-booleaness branch from a930e1f to 3377f77 Compare November 7, 2022 08:38
@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2022

πŸ€– Effect of this PR on checked open source code: πŸ€–

Effect on django:
The following messages are now emitted:

  1. use-implicit-booleaness-not-comparison:
    'inner_query.select == ()' can be simplified to 'not inner_query.select' as an empty tuple is falsey
    https://github.com/django/django/blob/444b6da7cc229a58a2c476a52e45233001dc7073/django/db/models/sql/query.py#L513

The following messages are no longer emitted:

  1. use-implicit-booleaness-not-comparison:
    'inner_query.select == ()' can be simplified to 'not inner_query.select' as an empty sequence is falsey
    https://github.com/django/django/blob/444b6da7cc229a58a2c476a52e45233001dc7073/django/db/models/sql/query.py#L513

Effect on pandas:
The following messages are now emitted:

  1. use-implicit-booleaness-not-comparison:
    'kwargs == {}' can be simplified to 'not kwargs' as an empty dict is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/_testing/asserters.py#L1247
  2. use-implicit-booleaness-not-comparison:
    'kwargs == {}' can be simplified to 'not kwargs' as an empty dict is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/_testing/asserters.py#L1250
  3. use-implicit-booleaness-not-comparison:
    's.attrs == {}' can be simplified to 'not s.attrs' as an empty dict is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/tests/series/test_api.py#L165
  4. use-implicit-booleaness-not-comparison:
    'df.attrs == {}' can be simplified to 'not df.attrs' as an empty dict is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/tests/frame/test_api.py#L318
  5. use-implicit-booleaness-not-comparison:
    'x == []' can be simplified to 'not x' as an empty list is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/tests/apply/test_frame_apply.py#L128
  6. use-implicit-booleaness-not-comparison:
    'reader.value_labels(...) == {}' can be simplified to 'not reader.value_labels(...)' as an empty dict is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/tests/io/test_stata.py#L604
  7. use-implicit-booleaness-not-comparison:
    'list(...) == []' can be simplified to 'not list(...)' as an empty list is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/tests/io/pytables/test_store.py#L107
  8. use-implicit-booleaness-not-comparison:
    'dicts == []' can be simplified to 'not dicts' as an empty list is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/io/xml.py#L376
  9. use-implicit-booleaness-not-comparison:
    'self._current_page_data_subheader_pointers != []' can be simplified to 'self._current_page_data_subheader_pointers' as an empty list is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/io/sas/sas7bdat.py#L389

The following messages are no longer emitted:

  1. use-implicit-booleaness-not-comparison:
    'kwargs == {}' can be simplified to 'not kwargs' as an empty sequence is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/_testing/asserters.py#L1247
  2. use-implicit-booleaness-not-comparison:
    'kwargs == {}' can be simplified to 'not kwargs' as an empty sequence is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/_testing/asserters.py#L1250
  3. use-implicit-booleaness-not-comparison:
    's.attrs == {}' can be simplified to 'not s.attrs' as an empty sequence is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/tests/series/test_api.py#L165
  4. use-implicit-booleaness-not-comparison:
    'df.attrs == {}' can be simplified to 'not df.attrs' as an empty sequence is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/tests/frame/test_api.py#L318
  5. use-implicit-booleaness-not-comparison:
    'x == []' can be simplified to 'not x' as an empty sequence is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/tests/apply/test_frame_apply.py#L128
  6. use-implicit-booleaness-not-comparison:
    'reader.value_labels(...) == {}' can be simplified to 'not reader.value_labels(...)' as an empty sequence is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/tests/io/test_stata.py#L604
  7. use-implicit-booleaness-not-comparison:
    'list(...) == []' can be simplified to 'not list(...)' as an empty sequence is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/tests/io/pytables/test_store.py#L107
  8. use-implicit-booleaness-not-comparison:
    'dicts == []' can be simplified to 'not dicts' as an empty sequence is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/io/xml.py#L376
  9. use-implicit-booleaness-not-comparison:
    'self._current_page_data_subheader_pointers != []' can be simplified to 'self._current_page_data_subheader_pointers' as an empty sequence is falsey
    https://github.com/pandas-dev/pandas/blob/0b931173c842a3476646b627422cf943d15288f6/pandas/io/sas/sas7bdat.py#L389

Effect on sentry:
The following messages are now emitted:

  1. no-member:
    Generator 'generator' has no 'enter' member
    https://github.com/getsentry/sentry/blob/7599f2dfd8eff4c14a7a3f254d45bd2fdb20ef96/src/sentry/utils/pytest/fixtures.py#L441
  2. no-member:
    Generator 'generator' has no 'exit' member
    https://github.com/getsentry/sentry/blob/7599f2dfd8eff4c14a7a3f254d45bd2fdb20ef96/src/sentry/utils/pytest/fixtures.py#L443
  3. use-implicit-booleaness-not-comparison:
    'list(...) == []' can be simplified to 'not list(...)' as an empty list is falsey
    https://github.com/getsentry/sentry/blob/7599f2dfd8eff4c14a7a3f254d45bd2fdb20ef96/src/sentry/replays/testutils.py#L58
  4. no-member:
    Generator 'generator' has no 'enter' member
    https://github.com/getsentry/sentry/blob/7599f2dfd8eff4c14a7a3f254d45bd2fdb20ef96/src/sentry/models/file.py#L214
  5. no-member:
    Generator 'generator' has no 'exit' member
    https://github.com/getsentry/sentry/blob/7599f2dfd8eff4c14a7a3f254d45bd2fdb20ef96/src/sentry/models/file.py#L216

The following messages are no longer emitted:

  1. use-implicit-booleaness-not-comparison:
    'list(...) == []' can be simplified to 'not list(...)' as an empty sequence is falsey
    https://github.com/getsentry/sentry/blob/7599f2dfd8eff4c14a7a3f254d45bd2fdb20ef96/src/sentry/replays/testutils.py#L58

This comment was generated for commit 3377f77

@mbyrnepr2
Copy link
Member

Are you concerned about the first two Sentry primer messages @Pierre-Sassoulas or can we ignore/they are unrelated?

@Pierre-Sassoulas
Copy link
Member Author

It would be very surprising if no-member was affected by this change, I think it's unrelated. We probably need to set the commit we lint for each repo on the primer to avoid that. We chose not to at implementation but we're ignoring those messages now and there's never a time where we check the new false positive. If we have to update the commit in a merge request that would be the time when we check those new messages and we would not bother about it right now.

Comment on lines +212 to +216
collection_literal = {
"list": "[]",
"tuple": "()",
"dict": "{}",
}.get(description, "iterable")
Copy link
Member

@mbyrnepr2 mbyrnepr2 Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder would it be best to factor this logic out and into the _get_node_description method? It is only used in this one place. Perhaps returning a tuple of description, collection_literal? You've looked into it more than I have so no problem if you disagree.

Copy link
Member Author

@Pierre-Sassoulas Pierre-Sassoulas Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it does not make a lot of sense right now but I'm going to use it use-implicit-booleaness-not-len later :) (there will also be list comprehension, dict comprension...)

Copy link
Member

@mbyrnepr2 mbyrnepr2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are on πŸ”₯πŸ”₯ @Pierre-Sassoulas

@Pierre-Sassoulas Pierre-Sassoulas merged commit f561753 into pylint-dev:main Nov 9, 2022
@Pierre-Sassoulas Pierre-Sassoulas deleted the more-actionnable-message-for-use-implicit-booleaness branch November 9, 2022 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation πŸ“— Skip news πŸ”‡ This change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants