-
Notifications
You must be signed in to change notification settings - Fork 2k
FURB188 calculates lengths wrong for non-ASCII affixes #13620
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
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ězecReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working