Skip to content

literal-membership (PLR6201)#

Derived from the Pylint linter.

Fix is always available.

This rule is unstable and in preview. The --preview flag is required for use.

What it does#

Checks for membership tests on list and tuple literals.

Why is this bad?#

When testing for membership in a static sequence, prefer a set literal over a list or tuple, as Python optimizes set membership tests.


1 in [1, 2, 3]

Use instead:

1 in {1, 2, 3}