Skip to content

PLR6201 fails but cannot be fixed on list in tuple(list, list) #9928

@gboeing

Description

@gboeing

Thanks for developing and supporting this wonderful tool! I'm using ruff 0.2.0. Say I have a bit of code to check if some list appears in a predefined collection of lists:

def f(x):
    list1 = [1, 2, 3]
    list2 = [4, 5, 6]
    return x in (list1, list2)

Running ruff . --preview fails with "PLR6201 Use a set literal when testing for membership"... which you certainly should do whenever you can, but you cannot in this case. Python lists are not hashable, so you cannot insert them into a set. If you try, like return x in {list1, list2}, you get "TypeError: unhashable type: 'list'".

PLR6201 should not fail in this case because it is unfixable. Instead, PLR6201 should only fail if the items in the membership test are hashable.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions