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

Emit consider-using-tuple for in comparisons #4853

Closed
wants to merge 3 commits into from

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Aug 16, 2021

Type of Changes

Type
✨ New feature

Description

Alternative to #4841
In contrast to #4768, with this PR consider-using-tuple will only be emitted for lists in in comparisons.

As discussed in #4776, this change will not have any impact on performance. CPython does this optimization when converting to bytecode.

# old
for x in [1, 2, 3]:
    ...

# new
for x in (1, 2, 3):
    ...

@cdce8p cdce8p added the Enhancement ✨ Improvement to a component label Aug 16, 2021
@cdce8p cdce8p marked this pull request as draft August 16, 2021 12:56
@coveralls
Copy link

coveralls commented Aug 16, 2021

Pull Request Test Coverage Report for Build 1152322179

  • 9 of 9 (100.0%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 92.743%

Totals Coverage Status
Change from base Build 1152045806: 0.003%
Covered Lines: 13458
Relevant Lines: 14511

💛 - Coveralls

@Pierre-Sassoulas
Copy link
Member

I thought the point of #4776 was to replace that by use-set-for-membership. Sets are the go to for in membership so if we don't recommend set we should not recommend something else imo. I don't think the problem with hashable being required for set is that huge, use-set-for-membership is salvageable, I'm just delaying it in 2.11 so we can think about it and get more opinions.

@cdce8p
Copy link
Member Author

cdce8p commented Aug 16, 2021

The reason I opened this one is that IMO we just shouldn't move forward with use-set-for-membership. The minimal performance improvement (if any at all) just isn't worth it. Dev's will overlook that it's a set when they add new items and then wonder why it isn't working. A False-Positive isn't worth it, not for this one.

If we don't recommend sets, there is still some value in using tuples instead. As the docstring for the checker mentions: even only for style consistency.

@Pierre-Sassoulas
Copy link
Member

I added more information in #4776 so the discussion can go on.

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.11.0 milestone Aug 17, 2021
@cdce8p cdce8p force-pushed the cs_tuple-in-comparison branch 2 times, most recently from 928df1e to 259bc71 Compare August 20, 2021 22:59
@cdce8p
Copy link
Member Author

cdce8p commented Aug 27, 2021

Closing this one, since we are going to move forward with #4841

@cdce8p cdce8p closed this Aug 27, 2021
@cdce8p cdce8p deleted the cs_tuple-in-comparison branch August 27, 2021 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants