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

PLR6201 on an empty list #15729

Closed
JelleZijlstra opened this issue Jan 24, 2025 · 1 comment · Fixed by #15732
Closed

PLR6201 on an empty list #15729

JelleZijlstra opened this issue Jan 24, 2025 · 1 comment · Fixed by #15732
Labels
bug Something isn't working preview Related to preview mode features rule Implementing or modifying a lint rule

Comments

@JelleZijlstra
Copy link
Contributor

Description

The preview rule PLR6201 turns 1 in [] into 1 in {}. Now, that code is pretty useless and Ruff should probably complain about it somehow, but turning [] into {} is problematic for a couple of reasons:

  • The rule says you should use a set, but {} is an empty dictionary, not an empty set.
  • It's strictly more likely to throw an error, because unhashable_object in {} raises an error.
  • It's slower (because it has to hash the object).

I'd recommend to not trigger PLR6201 on an empty collection, and possibly to add a separate lint rule that warns against in where the right-hand side is an empty collection.

@ntBre ntBre added bug Something isn't working fixes Related to suggested fixes for violations labels Jan 24, 2025
@dylwil3
Copy link
Collaborator

dylwil3 commented Jan 25, 2025

Thanks again for the PR @JelleZijlstra and feel free to open another issue about

and possibly to add a separate lint rule that warns against in where the right-hand side is an empty collection.

if you feel motivated to do so!

@AlexWaygood AlexWaygood added rule Implementing or modifying a lint rule preview Related to preview mode features and removed fixes Related to suggested fixes for violations labels Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants