Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLC0208 should only recommend fixes when iterating over literals #11694

Open
Skylion007 opened this issue Jun 2, 2024 · 2 comments
Open

PLC0208 should only recommend fixes when iterating over literals #11694

Skylion007 opened this issue Jun 2, 2024 · 2 comments
Labels
rule Implementing or modifying a lint rule

Comments

@Skylion007
Copy link

Skylion007 commented Jun 2, 2024

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.

@Skylion007
Copy link
Author

Ugh, looks like #4907 it suppose to cover this, but fails with parameters or getter calls.

@charliermarsh
Copy link
Member

I think this is different than #4907? My read is that change was about comprehensions and set calls. Pylint does flag the cases you've included here, though we could consider changing our rule.

@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

2 participants