Skip to content

PLC0208 should only recommend fixes when iterating over literals #11694

@Skylion007

Description

@Skylion007

I tried PLC0208 on my codebase, and found several spots where iterating over a set was clearly intentional. Here is a salient example:

for rg in {dtype.is_floating_point, False}:

This will would get corrected to a sequence, when I want this test case to run over True and False is dtype.is_floating_point is true. Otherwise, only False.

Another useful idiom is:

for index in {0, sparse.shape[dim] // 2, sparse.shape[dim] - 1}:

Where I want to loop over all unique values. If the sparse.shape[dim] is 2, then I only go over index (0, 1) instead of (0, 1, 1). It doesn't seem like this fix can be safe if it doesn't know what it's referencing. At the very least, the fix should be marked unsafe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing 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