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

FURB188 calculates lengths wrong for non-ASCII affixes #13620

Closed
dscorbett opened this issue Oct 3, 2024 · 1 comment · Fixed by #13631
Closed

FURB188 calculates lengths wrong for non-ASCII affixes #13620

dscorbett opened this issue Oct 3, 2024 · 1 comment · Fixed by #13631
Labels
bug Something isn't working

Comments

@dscorbett
Copy link

slice-to-remove-prefix-or-suffix (FURB188) determines string length by UTF-8 code units, as in Rust, whereas Python counts code points. This discrepancy causes problems for non-ASCII affixes. In the following, furb188.py has two parts: the first has a false positive and the second has a false negative.

$ ruff --version
ruff 0.6.8
$ cat furb188.py
text = "řetězec"
if text.startswith("ř"):
    text = text[2:]
print(text)

text = "řetězec"
if text.startswith("ř"):
    text = text[1:]
print(text)
$ python furb188.py
tězec
etězec
$ ruff check --isolated --preview --target-version py39 --select FURB188 furb188.py --fix
Found 1 error (1 fixed, 0 remaining).
$ cat furb188.py
text = "řetězec"
text = text.removeprefix("ř")
print(text)

text = "řetězec"
if text.startswith("ř"):
    text = text[1:]
print(text)
$ python furb188.py
etězec
etězec
@dylwil3
Copy link
Collaborator

dylwil3 commented Oct 4, 2024

Thank you! I'll try to fix this shortly.

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