missing-maxsplit-arg (PLC0207)
Derived from the Pylint linter.
Fix is always available.
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()
or str.rsplit()
without
maxsplit=1
Why is this bad?
Calling str.split()
or str.rsplit()
without passing maxsplit=1
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
Use instead:
To access the last element, use str.rsplit()
instead of str.split()
:
Fix Safety
This rule's fix is marked as unsafe for split()
/rsplit()
calls that contain *args
or **kwargs
arguments, as
adding a maxsplit
argument to such a call may lead to duplicated arguments.