-
Notifications
You must be signed in to change notification settings - Fork 61
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
Resolving Issue #699 - Fix runtime error #712
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lorena-b great detective work. For the issue of the checker no longer working, you determined that the Index
node is no longer available, and replaced that with accessing the Subscript
directly.
However, this is a change in Python 3.9, so the tests are now failing in Python 3.8. In cases like this, we can check sys.version
(imported from the sys
module) to see what the current version of Python is, and then based on the result execute different branches of code. You should do this for the is_load_subscript
function.
Motivation and Context
This pull request is required to resolve #699. This change resolves a runtime error which occurs when running the
UnnecessaryIndexingChecker
on a block of code where an assignment node has an empty scope.This pull request also fixes functions that no longer worked correctly due to changes in the astroid node representation, which caused the example file cases to fail.
Your Changes
Description:
This change handles the case where the second argument of the tuple returned by
node.lookup()
is an empty tuple so that an index error does not occur._is_load_subscript()
helper function was rewritten to produce the correct output.Type of change (select all that apply):
Testing
In order to test this change a test suite was created for this checker using pylints testing capabilities. The checker was tested with the example code and the code that raised the original error.
Questions and Comments (if applicable)
The tests for the code examples are failing because the checker seems to not have been implemented correctly. I am trying to figure out what is wrong with the current implementation that makes the checker not work even in basic cases.
Update:
_is_load_subscript()
helper function due to changes in the astroid node representation. When indexing the iterable the Name node now directly has a Subscript as the parent, instead of having an Index node in between.Checklist