Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix potential-index-error false positive when iterable contains starred element#10097

Merged
DanielNoord merged 3 commits into
pylint-dev:mainfrom
zenlyj:fix/10076-false-positive
Nov 24, 2024
Merged

Fix potential-index-error false positive when iterable contains starred element#10097
DanielNoord merged 3 commits into
pylint-dev:mainfrom
zenlyj:fix/10076-false-positive

Conversation

@zenlyj
Copy link
Copy Markdown
Contributor

@zenlyj zenlyj commented Nov 24, 2024

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
📜 Docs

Description

The current implementation calculates the length of an indexed iterable by using its literal length. However, this approach fails when the iterable contains a starred element that unpacks into multiple elements.

For example:

lst = [1, 2, 3]
print([*lst][1])  # error reported as checker assumes indexed iterable has 1 element instead of 3.

This PR addresses the issue by extending the check to account for the inferred length of starred nodes within the indexed iterable.

Closes #10076

@zenlyj zenlyj added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Nov 24, 2024
@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 24, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.80%. Comparing base (68cb5b3) to head (9e865b4).
⚠️ Report is 392 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #10097   +/-   ##
=======================================
  Coverage   95.80%   95.80%           
=======================================
  Files         174      174           
  Lines       18962    18973   +11     
=======================================
+ Hits        18166    18177   +11     
  Misses        796      796           
Files with missing lines Coverage Δ
pylint/checkers/variables.py 97.27% <100.00%> (+0.02%) ⬆️
🚀 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.

@zenlyj zenlyj force-pushed the fix/10076-false-positive branch from d627b12 to 9e865b4 Compare November 24, 2024 06:59
@github-actions
Copy link
Copy Markdown
Contributor

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit 9e865b4

Copy link
Copy Markdown
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.

Looks great, thank you!

@DanielNoord DanielNoord merged commit 3e9e613 into pylint-dev:main Nov 24, 2024
github-actions Bot pushed a commit that referenced this pull request Nov 24, 2024
Pierre-Sassoulas pushed a commit that referenced this pull request Nov 24, 2024
…rred element (#10097) (#10098)

(cherry picked from commit 3e9e613)

Co-authored-by: Zen Lee <[email protected]>
@zenlyj zenlyj deleted the fix/10076-false-positive branch November 25, 2024 10:21
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.

Rule E0643 behaves inconsistently when indexing tuples

3 participants