Skip to content

missing-maxsplit-arg (PLC0207)

Derived from the Pylint linter.

This rule is unstable and in preview. The --preview flag is required for use.

What it does

Checks for access to the first or last element of str.split() without maxsplit=1

Why is this bad?

Calling str.split() without maxsplit set splits on every delimiter in the string. When accessing only the first or last element of the result, it would be more efficient to only split once.

Example

url = "www.example.com"
prefix = url.split(".")[0]

Use instead:

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