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

Avoid raising undefined-loop-variable twice on same line #6925

Merged

Conversation

jacobtylerwalls
Copy link
Member

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

See #6923 (comment) for report.

This call has been here since the initial commit, but nothing fails when I remove it. Let's see what the primer says.

@jacobtylerwalls jacobtylerwalls added Needs backport Needs to be cherry-picked on the current patch version by a pylint's maintainer False Positive 🦟 A message is emitted but nothing is wrong with the code labels Jun 12, 2022
@jacobtylerwalls jacobtylerwalls added this to the 2.14.2 milestone Jun 12, 2022
@coveralls
Copy link

Pull Request Test Coverage Report for Build 2483725205

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.0003%) to 95.528%

Totals Coverage Status
Change from base Build 2483640983: -0.0003%
Covered Lines: 16386
Relevant Lines: 17153

πŸ’› - Coveralls

@github-actions
Copy link
Contributor

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

Effect on black:
The following messages are no longer emitted:

  1. undefined-loop-variable:
    Using possibly undefined loop variable 'directory'
    https://github.com/psf/black/blob/main/src/black/files.py#L81
  2. undefined-loop-variable:
    Using possibly undefined loop variable 'current'
    https://github.com/psf/black/blob/main/src/blib2to3/pytree.py#L378

Effect on pandas:
The following messages are no longer emitted:

  1. undefined-loop-variable:
    Using possibly undefined loop variable 's'
    https://github.com/pandas-dev/pandas/blob/main/pandas/tests/frame/test_iteration.py#L162
  2. undefined-loop-variable:
    Using possibly undefined loop variable '_df'
    https://github.com/pandas-dev/pandas/blob/main/pandas/tests/frame/methods/test_to_dict_of_blocks.py#L28
  3. undefined-loop-variable:
    Using possibly undefined loop variable '_df'
    https://github.com/pandas-dev/pandas/blob/main/pandas/tests/frame/methods/test_to_dict_of_blocks.py#L42
  4. undefined-loop-variable:
    Using possibly undefined loop variable 's'
    https://github.com/pandas-dev/pandas/blob/main/pandas/tests/strings/test_strings.py#L64
  5. undefined-loop-variable:
    Using possibly undefined loop variable 'obj'
    https://github.com/pandas-dev/pandas/blob/main/pandas/tests/io/formats/test_printing.py#L144
  6. undefined-loop-variable:
    Using possibly undefined loop variable 'i'
    https://github.com/pandas-dev/pandas/blob/main/pandas/core/util/hashing.py#L79
  7. undefined-loop-variable:
    Using possibly undefined loop variable 'i'
    https://github.com/pandas-dev/pandas/blob/main/pandas/io/formats/style.py#L2350
  8. undefined-loop-variable:
    Using possibly undefined loop variable 'max_items'
    https://github.com/pandas-dev/pandas/blob/main/pandas/io/formats/printing.py#L423
  9. undefined-loop-variable:
    Using possibly undefined loop variable 'max_items'
    https://github.com/pandas-dev/pandas/blob/main/pandas/io/formats/printing.py#L424
  10. undefined-loop-variable:
    Using possibly undefined loop variable 'pad'
    https://github.com/pandas-dev/pandas/blob/main/pandas/io/formats/latex.py#L162
  11. undefined-loop-variable:
    Using possibly undefined loop variable 'asheetname'
    https://github.com/pandas-dev/pandas/blob/main/pandas/io/excel/_base.py#L860

Effect on psycopg:
The following messages are no longer emitted:

  1. undefined-loop-variable:
    Using possibly undefined loop variable 'ent'
    https://github.com/psycopg/psycopg/blob/master/psycopg/psycopg/_dns.py#L330
  2. undefined-loop-variable:
    Using possibly undefined loop variable 'ent'
    https://github.com/psycopg/psycopg/blob/master/psycopg/psycopg/_dns.py#L331
  3. undefined-loop-variable:
    Using possibly undefined loop variable 'm'
    https://github.com/psycopg/psycopg/blob/master/psycopg/psycopg/types/composite.py#L120
  4. undefined-loop-variable:
    Using possibly undefined loop variable 'm'
    https://github.com/psycopg/psycopg/blob/master/psycopg/psycopg/types/composite.py#L120

Effect on pytest:
The following messages are no longer emitted:

  1. undefined-loop-variable:
    Using possibly undefined loop variable 'iterated_index'
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/assertion/truncate.py#L89
  2. undefined-loop-variable:
    Using possibly undefined loop variable 'i'
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/assertion/rewrite.py#L499
  3. undefined-loop-variable:
    Using possibly undefined loop variable 'i'
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/assertion/rewrite.py#L499
  4. undefined-loop-variable:
    Using possibly undefined loop variable 'item'
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/assertion/rewrite.py#L709
  5. undefined-loop-variable:
    Using possibly undefined loop variable 'item'
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/assertion/rewrite.py#L709
  6. undefined-loop-variable:
    Using possibly undefined loop variable 'item'
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/assertion/rewrite.py#L710
  7. undefined-loop-variable:
    Using possibly undefined loop variable 'item'
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/assertion/rewrite.py#L712

Effect on sentry:
The following messages are no longer emitted:

  1. undefined-loop-variable:
    Using possibly undefined loop variable 'event'
    https://github.com/getsentry/sentry/blob/master/src/sentry/similarity/features.py#L142
  2. undefined-loop-variable:
    Using possibly undefined loop variable 'event'
    https://github.com/getsentry/sentry/blob/master/src/sentry/similarity/features.py#L186
  3. undefined-loop-variable:
    Using possibly undefined loop variable 'component'
    https://github.com/getsentry/sentry/blob/master/src/sentry/grouping/strategies/hierarchical.py#L55
  4. undefined-loop-variable:
    Using possibly undefined loop variable 'component'
    https://github.com/getsentry/sentry/blob/master/src/sentry/grouping/strategies/hierarchical.py#L57

This comment was generated for commit bce0514

@jacobtylerwalls
Copy link
Member Author

I spot-checked the messages from sentry, and found that they were duplicates that are now just emitted once.

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

While checking if self._loopvar_name(node) is still being used I noticed that the other use is guarded by if self._is_undefined_loop_variable_enabled.

This breaks useless-suppression. We could fix that in this PR as well or do a follow-up.

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.

πŸ‘Œ

@Pierre-Sassoulas Pierre-Sassoulas merged commit 8440e24 into pylint-dev:main Jun 12, 2022
@Pierre-Sassoulas
Copy link
Member

Nice catch @DanielNoord. Let's do a follow-up as it's another issue.

@jacobtylerwalls jacobtylerwalls deleted the undefined-loop-twice branch June 12, 2022 15:28
@Pierre-Sassoulas Pierre-Sassoulas added Backported and removed Needs backport Needs to be cherry-picked on the current patch version by a pylint's maintainer labels Jun 15, 2022
Pierre-Sassoulas pushed a commit to Pierre-Sassoulas/pylint that referenced this pull request Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants