You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
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
Description
The preview rule
PLR6201
turns1 in []
into1 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:{}
is an empty dictionary, not an empty set.unhashable_object in {}
raises an error.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.The text was updated successfully, but these errors were encountered: