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

PLR1736 yields invalid suggestion and unsafe fix that changes semantics. #8969

Closed
Skylion007 opened this issue Dec 2, 2023 · 4 comments · Fixed by #8970
Closed

PLR1736 yields invalid suggestion and unsafe fix that changes semantics. #8969

Skylion007 opened this issue Dec 2, 2023 · 4 comments · Fixed by #8970
Labels
bug Something isn't working

Comments

@Skylion007
Copy link
Contributor

Skylion007 commented Dec 2, 2023

l = list(range(1, 10))
b = []
for i, a in enumerate(l):
    if a < 5:
        a = -a
    b.append(l[i])
assert b == l, "b and l should match"

but it gets flagged and transform by the fixes into

l = list(range(1, 10))
b = []
for i, a in enumerate(l):
    if a < 5:
        a = -a
    b.append(a)
assert b == l, "b and l should match"

which is wrong and now fails the assert. Seems like the refactor may have missed this test case. I ran this test on the PR before it was merged a few weeks agi and it ran fine so it might have something to do with either last minute changes to the PR or changes @charliermarsh made to the PR after it was merged (#8932). This is a contrived example with an unused, but it's simplified from a real failure case in torch/optim/adamw.py in the pytorch repo.

Current ruff version is a build done on the latest master as of today 2023/12/2.

@Skylion007
Copy link
Contributor Author

I flagged a similar issue here: #7999 (comment) in the PR, but that one appeared to be fixed.

@charliermarsh
Copy link
Member

Thanks, will fix. Just confirming, this isn’t released yet, right?

@Skylion007
Copy link
Contributor Author

Skylion007 commented Dec 2, 2023

Correct, and it's still a preview rule.

@charliermarsh
Copy link
Member

Awesome, thanks for reporting from main!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants