Skip to content

Conversation

LaBatata101
Copy link
Contributor

Summary

The fix would create a syntax error if there wasn't a space between the in keyword and the following expression.
For example:

for country, stars in(zip)(flag_stars.keys(), flag_stars.values()):...

I also noticed that the tests for SIM911 were note being run, so I fixed that.

Fixes #18776

Test Plan

Add regression test

Copy link
Contributor

github-actions bot commented Jun 19, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MeGaGiGaGon
Copy link
Contributor

I think this wouldn't work in all cases, since it's explicitly checking for in, but you can have a lot of other syntax elements there, for example or playground

My guess is the correct thing to do would be to use fix::edits::pad like in #7699

@LaBatata101
Copy link
Contributor Author

I think this wouldn't work in all cases, since it's explicitly checking for in, but you can have a lot of other syntax elements there, for example or playground

For that case it fixes with no issue

--- sample2.py
+++ sample2.py
@@ -1,2 +1,2 @@
 flag_stars = {}
-for country, stars in 1or(zip)(flag_stars.keys(), flag_stars.values()):...
+for country, stars in 1or flag_stars.items():...

My guess is the correct thing to do would be to use fix::edits::pad like in #7699

Cool, didn't know that function. I'll try to update the solution.

@MeGaGiGaGon
Copy link
Contributor

I think it worked there because there happened to be whitespace between the in and next expr that isn't the zip that's being removed. That should make these cases fail since they don't have that whitespace: playground

@LaBatata101
Copy link
Contributor Author

I think it worked there because there happened to be whitespace between the in and next expr that isn't the zip that's being removed. That should make these cases fail since they don't have that whitespace: playground

Should be fine now, I've updated to use edits::pad

@@ -101,7 +102,11 @@ pub(crate) fn zip_dict_keys_and_values(checker: &Checker, expr: &ast::ExprCall)
return;
}

let expected = format!("{}.items()", checker.locator().slice(var1));
let expected = edits::pad(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I didn't know this existed

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@MichaReiser MichaReiser added bug Something isn't working fixes Related to suggested fixes for violations labels Jun 23, 2025
@MichaReiser MichaReiser self-requested a review June 23, 2025 08:57
@MichaReiser MichaReiser merged commit 9e9c4fe into astral-sh:main Jun 23, 2025
35 checks passed
@LaBatata101 LaBatata101 deleted the fix-SIM911 branch June 23, 2025 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flake8-simplify] SIM911 fix causes syntax error
3 participants