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

E251 from spaces around equals in f-string in function argument #7882

Closed
mymoomin opened this issue Oct 10, 2023 · 2 comments · Fixed by #7894
Closed

E251 from spaces around equals in f-string in function argument #7882

mymoomin opened this issue Oct 10, 2023 · 2 comments · Fixed by #7894
Assignees
Labels
bug Something isn't working

Comments

@mymoomin
Copy link

On Ruff version 0.0.292, ruff --preview --isolated will misinterpret spaces around equals in f-strings that are function arguments as spaces around keyword arguments and raise an error.

a = 1
b = f"{a = }"  # This is fine
print(a = 1)  # Expected E251 Unexpected spaces around keyword / parameter equals
print(f"{a = }")  # Unexpected E251
@charliermarsh
Copy link
Member

Thanks! \cc @dhruvmanila who fixed a few of these prior to release.

@charliermarsh charliermarsh added the bug Something isn't working label Oct 10, 2023
mymoomin added a commit to mymoomin/RSStoWebhook that referenced this issue Oct 10, 2023
Ruff currently has a bug astral-sh/ruff#7882 that means spaces in
f-strings are sometimes interpretted as spaces around keyword arguments.

This silences the error until it is fixed.
@dhruvmanila dhruvmanila self-assigned this Oct 10, 2023
dhruvmanila added a commit that referenced this issue Oct 12, 2023
## Summary

This PR fixes the bug where the rule `E251` was being triggered on a equal token
inside a f-string which was used in the context of debug expressions.

For example, the following was being flagged before the fix:

```python
print(f"{foo = }")
```

But, now it is not. This leads to false negatives such as:

```python
print(f"{foo(a = 1)}")
```

One solution would be to know if the opened parentheses was inside a f-string or
not. If it was then we can continue flagging until it's closed. If not, then we
should not flag it.

## Test Plan

Add new test cases and check that they don't raise any false positives.

fixes: #7882
@mymoomin
Copy link
Author

Thank you for the incredibly fast fix!

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.

3 participants