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

TypeError in unnecessary-list-index-lookup #6049

Closed
jacobtylerwalls opened this issue Mar 30, 2022 · 4 comments · Fixed by #6061
Closed

TypeError in unnecessary-list-index-lookup #6049

jacobtylerwalls opened this issue Mar 30, 2022 · 4 comments · Fixed by #6061
Labels
Crash 💥 A bug that makes pylint crash
Milestone

Comments

@jacobtylerwalls
Copy link
Member

Bug description

pairs = [(0, 0)]
for i, (a, b) in enumerate(pairs):
    print(pairs[i][0])

Configuration

No response

Command used

pylint a.py

Pylint output

Exception on node <For l.2 at 0x106f22e00> in file '/Users/.../.../a.py'
Traceback (most recent call last):
  File "/Users/.../pylint/pylint/utils/ast_walker.py", line 73, in walk
    callback(astroid)
  File "/Users/.../pylint/pylint/checkers/refactoring/refactoring_checker.py", line 651, in visit_for
    self._check_unnecessary_list_index_lookup(node)
  File "/Users/.../pylint/pylint/checkers/refactoring/refactoring_checker.py", line 2037, in _check_unnecessary_list_index_lookup
    and index.lookup(value_variable.name)[1][-1].lineno
TypeError: '>' not supported between instances of 'NoneType' and 'int'

Expected behavior

no crash, and potentially, a message to use a and not [i][0]

Pylint version

pylint 2.14.0-dev0
astroid 2.12.0-dev0
Python 3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang 13.0.0 (clang-1300.0.29.30)]

OS / Environment

No response

Additional dependencies

No response

@jacobtylerwalls jacobtylerwalls added Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling Crash 💥 A bug that makes pylint crash and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Mar 30, 2022
@jacobtylerwalls
Copy link
Member Author

FYI @timmartin -- perhaps you would like to take a look? Would be much appreciated.

@jacobtylerwalls jacobtylerwalls added this to the 2.14.0 milestone Mar 30, 2022
@timmartin
Copy link
Contributor

Sure, I'll take a look at this.

@DanielNoord
Copy link
Collaborator

@jacobtylerwalls Not sure how you found this, but is this project a potential candidate for the primer?

@jacobtylerwalls
Copy link
Member Author

is this project a potential candidate for the primer?

Sure. It's music21, which I help maintain. I've used it to report issues like #4891 #4664 and #6074. And I should be able to help contributors interpret behavior changes if we get the message-differ wired up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants