-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violations
Description
Summary
The fix for split-static-string (SIM905) changes the behavior of str.split with sep=None (the default) and maxsplit=0 if the string is empty or begins with white space. The output of split should not contain an empty string or a string beginning with white space. Similarly, the fix breaks str.rsplit if the string is empty or ends with white space.
$ cat >sim905.py <<'# EOF'
print("".split(maxsplit=0))
print(" ".split(maxsplit=0))
print(" x ".split(maxsplit=0))
print("".rsplit(maxsplit=0))
print(" ".rsplit(maxsplit=0))
print(" x ".rsplit(maxsplit=0))
# EOF
$ python sim905.py
[]
[]
['x ']
[]
[]
[' x']
$ ruff --isolated check sim905.py --select SIM905 --fix
Found 6 errors (6 fixed, 0 remaining).
$ python sim905.py
['']
[' ']
[' x ']
['']
[' ']
[' x ']Version
ruff 0.11.9 (2370297 2025-05-09)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violations