Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Fix crash while iteraring over a class attribute #7386
Fix crash while iteraring over a class attribute #7386
Changes from 1 commit
5fe8a2c
2b3e733
339abe2
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
This is the only class in the test file. you can add the disable flag at the top of the file
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.
This is personal preference I think. I like disabling at the occurrence as it allows more freedom in checking for some message further down the file.
But I'll change it here 😄
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.
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.
Also check the false positive case. Fix the
.txt
file accordingly.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.
I think we should hold off on actually fixing any false negatives and positives here. As I said, the current code really doesn't work well with class attributes as we depend on functions like
.append
being attributes of the iterable object. This complicates things massively when actually looking for attributes.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.
@DanielNoord yeah i re-read it and understood that the case which is not working is the class case.
I don't fully understand the
append
example, how can you putlist.append
in a for loop?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.
The issue here is that
append
is anAttribute
node ona_list
just asattribute
is anAttribute
node in the following example:Astroid
only recognises that they are nodes that come after a period, not that they are attributes in the traditional sense of the word.This complicates the logic we're currently using in the checker. I tried to fix it, but it turned out to be a pretty large refactor which probably should be taken in multiple steps for ease of reviewing.
To make sure we no longer crash I wanted to push this fix at least.
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.
You mean like when iterating through a dictionary
d
: iterating ond.keys
is anAttribute
which is actually a fix the our error of iterating throughd
? something like that? so your current solution will throw false-postive now?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.
I think you'll understand what you mean when you add the example I gave in the opening post to the functional tests. If you run
pytest
then you'll see that some of theisinstance(node, nodes.Attribute)
test you are using to pick upd.append
will now also pick upMyClass.attribute
. This causes some issues and methods such as_modified_iterating_list_cond
will need to be changed to allow checking both type of nodes.