Skip to content

PY-COLL0003 · local_collection_representation_candidate

Recommend list, tuple, or set only when local use proves interchangeability.

This is a deterministic rule for python. Read its implementation.

Inspect unannotated local list and tuple literals containing at least two literal values of one kind. The candidate is a name one callable binds exactly once, so every read of it is inside that callable and can be counted. If every read is the iterable of a loop or a comprehension, recommend the configured sequence form, which defaults to list. If every read is a membership test and the values are distinct, recommend set when enabled. One read that is neither leaves both claims unproven and the rule abstains.

Continue with evidence and references, or open the examples.