Skip to content

PLR6201 on an empty list #15729

@JelleZijlstra

Description

@JelleZijlstra

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpreviewRelated to preview mode featuresruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions