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

SIM110 with a yield in the condition #7800

Closed
JelleZijlstra opened this issue Oct 4, 2023 · 0 comments · Fixed by #7801
Closed

SIM110 with a yield in the condition #7800

JelleZijlstra opened this issue Oct 4, 2023 · 0 comments · Fixed by #7801

Comments

@JelleZijlstra
Copy link
Contributor

Using SIM110 I ran into this change:

-        for p in self.predicates:
-            if not (yield p.is_satisfied.asynq()):  # noqlint
-                return False
-        return True
+        return all((yield p.is_satisfied.asynq()) for p in self.predicates)

This code is using the asynq framework, causing the unusual yield. Ruff should not apply this fix if there is a yield in the condition, as the yield will end up in the inner generator expression, where it is a SyntaxError in recent Python versions.

While looking at the code I noticed that Ruff already protects against this class of bug with await, but the protection is slightly too eager: it applies if there is an await in the for loop's iter expression. However, the iter expression of a genexp is evaluated in the outer scope, so it's fine if there's an await there.

I will submit a PR soon with a proposed fix.

Also worth noting that Ruff ate the comment here. That feels like a bug too, but it's probably more involved to fix so I'll skip it for now.

JelleZijlstra added a commit to JelleZijlstra/ruff that referenced this issue Oct 4, 2023
And allow "await" in the loop iterable.

Fixes astral-sh#7800
JelleZijlstra added a commit to JelleZijlstra/ruff that referenced this issue Oct 4, 2023
And allow "await" in the loop iterable.

Fixes astral-sh#7800
charliermarsh pushed a commit that referenced this issue Oct 4, 2023
And allow "await" in the loop iterable.

Fixes #7800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant