Skip to content

Conversation

@emmanuel-ferdman
Copy link
Contributor

@emmanuel-ferdman emmanuel-ferdman commented Sep 17, 2025

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Pylint incorrectly reported undefined-variable (E0602) for code like:

item = (1, 2, 3)
for item in item:  # E0602: Undefined variable 'item'
  print(item)

The problem is that in get_next_to_consume(), the for-loop detection logic always set found_nodes = None even when detecting for X in X: patterns, which eventually triggers the fallback undefined-variable error. The solution updates the logic to distinguish between two cases:

  • Variable reuse: item = 1; for item in item: - In this case, keep original definition.
  • Undefined reference: for iteree in iteree: - In this case, trigger error.

Closes #10562

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.

Thank you for opening this PR :)

@codecov
Copy link

codecov bot commented Sep 18, 2025

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 95.90%. Comparing base (5b39db3) to head (fd8fc82).
⚠️ Report is 64 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #10569   +/-   ##
=======================================
  Coverage   95.90%   95.90%           
=======================================
  Files         176      176           
  Lines       19453    19456    +3     
=======================================
+ Hits        18656    18659    +3     
  Misses        797      797           
Files with missing lines Coverage Ξ”
pylint/checkers/variables.py 97.41% <100.00%> (+<0.01%) ⬆️
πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

This comment has been minimized.

@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code backport maintenance/4.0.x labels Sep 18, 2025
@Pierre-Sassoulas Pierre-Sassoulas added this to the 3.3.9 milestone Sep 18, 2025
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.

Great ! Let's rename doc/whatsnew/fragments/10562.bugfix.rst to doc/whatsnew/fragments/10562.bugfix and merge this :)

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

πŸ€– According to the primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

This comment was generated for commit fd8fc82

@Pierre-Sassoulas Pierre-Sassoulas merged commit ed6b306 into pylint-dev:main Sep 19, 2025
44 checks passed
pylint-backport bot pushed a commit that referenced this pull request Sep 19, 2025
Signed-off-by: Emmanuel Ferdman <[email protected]>
(cherry picked from commit ed6b306)
Pierre-Sassoulas pushed a commit that referenced this pull request Sep 19, 2025
(cherry picked from commit ed6b306)

Signed-off-by: Emmanuel Ferdman <[email protected]>
Co-authored-by: Emmanuel Ferdman <[email protected]>
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.

False positive for E0602?

2 participants