Skip to content

missing-maxsplit-arg (PLC0207) is wrong when accessing on the last value #18383

@fedexman

Description

@fedexman

Summary

>>> url = "www.example.com"
>>> url.split(".", maxsplit=1)[0]
'www'
>>> url.split(".", maxsplit=1)[-1]
'example.com'
>>> url.split(".")[-1]
'com'

we can see the the maxsplit change the result when getting the last element, but ruff suggest: PLC0207 Accessing only the first or last element of str.split() without setting maxsplit=1
but this rule doesn't make sense for the last element, it should only be suggested for the first element, or I'm missing something 🤔

Version

ruff 0.11.12 (aee3af0 2025-05-29)

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationhelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions