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

E203 false positives for slices in format strings #10278

Closed
sciyoshi opened this issue Mar 7, 2024 · 1 comment · Fixed by #10280
Closed

E203 false positives for slices in format strings #10278

sciyoshi opened this issue Mar 7, 2024 · 1 comment · Fixed by #10280
Labels
bug Something isn't working

Comments

@sciyoshi
Copy link
Contributor

sciyoshi commented Mar 7, 2024

Sample code:

a = f"{1[1 - 2 :]}"
b = 1[1 - 2 :]

When running with ruff --select E203 --preview, the first line triggers E203:

test.py:1:15: E203 [*] Whitespace before ':'
  |
1 | a = f"{1[1 - 2 :]}"
  |               ^ E203
  |
  = help: Remove whitespace before ':'

The same slice on the second line which is outside of a format string does not trigger E203.

sciyoshi added a commit to sciyoshi/ruff that referenced this issue Mar 7, 2024
@charliermarsh charliermarsh added the bug Something isn't working label Mar 7, 2024
charliermarsh pushed a commit that referenced this issue Mar 7, 2024
## Summary

The code later in this file that checks for slices relies on the stack
of brackets to determine the position. I'm not sure why format strings
were being excluded from this, but the tests still pass with these match
guards removed.

Closes #10278

## Test Plan

~Still needs a test.~ Test case added for this example.
@charliermarsh
Copy link
Member

Thanks for the PR as always.

nkxxll pushed a commit to nkxxll/ruff that referenced this issue Mar 10, 2024
## Summary

The code later in this file that checks for slices relies on the stack
of brackets to determine the position. I'm not sure why format strings
were being excluded from this, but the tests still pass with these match
guards removed.

Closes astral-sh#10278

## Test Plan

~Still needs a test.~ Test case added for this example.
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