zip-without-explicit-strict (B905)#
Derived from the flake8-bugbear linter.
Fix is always available.
What it does#
Checks for zip
calls without an explicit strict
parameter.
Why is this bad?#
By default, if the iterables passed to zip
are of different lengths, the
resulting iterator will be silently truncated to the length of the shortest
iterable. This can lead to subtle bugs.
Use the strict
parameter to raise a ValueError
if the iterables are of
non-uniform length. If the iterables are intentionally different lengths, the
parameter should be explicitly set to False
.
Example#
Use instead:
Fix safety#
This rule's fix is marked as unsafe for zip
calls that contain
**kwargs
, as adding a strict
keyword argument to such a call may lead
to a duplicate keyword argument error.