Skip to content

SIM905 fix for rsplit is reversed #18042

@dscorbett

Description

@dscorbett

Summary

The list produced for rsplit by split-static-string (SIM905) is the reverse of what it should be.

$ cat >sim905.py <<'# EOF'
print("a,b".rsplit(","))
# EOF

$ python sim905.py
['a', 'b']

$ ruff --isolated check sim905.py --select SIM905 --fix
Found 1 error (1 fixed, 0 remaining).

$ cat sim905.py
print(["b", "a"])

$ python sim905.py
['b', 'a']

This is because the fix is implemented with Rust’s str::rsplit and str::rsplitn, which return iterators over the string in reverse, unlike Python’s str.rsplit.

Version

ruff 0.11.9 (2370297 2025-05-09)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violationshelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions