-
Notifications
You must be signed in to change notification settings - Fork 2
fix: prevent sets from being reported as InPlaceSortAnalysis warnings #4
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
Conversation
AryazE
left a comment
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.
Thank you for the PR.
Yes, this seems like a problem.
However, I think the fix you suggested restricts the checker too much. I think any collection or object that has .sort and has a length (too check for long sequences) should be caught.
I have made a suggestion for the change.
Could you also extend the tests with such cases?
| if function is sorted: | ||
| # we have to keep the list in memory to keep id(pos_args[0]) stable ? nope! | ||
| if hasattr(pos_args[0], "__len__") and len(pos_args[0]) > self.threshold: | ||
| if type(pos_args[0]) is list and len(pos_args[0]) > self.threshold: |
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.
| if type(pos_args[0]) is list and len(pos_args[0]) > self.threshold: | |
| if hasattr(pos_args[0], "sort") and hasattr(pos_args[0], "__len__") and len(pos_args[0]) > self.threshold: |
|
I made the changes. I also made a small refactor that I thought would be nice to reduce repetition. |
AryazE
left a comment
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.
Thanks for the update.
I have renamed the function and added some tests.
|
It look great, thanks! |

Hi @AryazE,
I’ve noticed that
InPlaceSortAnalysisincorrectly raises warnings forSetobjects, even though sets can't be sorted and don’t have an in-place.sort()method.For example:
I’ve implemented a simple fix for this. Please have a look and let me know if any further changes are needed.