map-without-explicit-strict (B912)
Derived from the flake8-bugbear linter.
Fix is always available.
This rule is unstable and in preview. The --preview
flag is required for use.
What it does
Checks for map
calls without an explicit strict
parameter when called with two or more iterables.
This rule applies to Python 3.14 and later, where map
accepts a strict
keyword
argument. For details, see: What’s New in Python 3.14.
Why is this bad?
By default, if the iterables passed to map
are of different lengths, the
resulting iterator will be silently truncated to the length of the shortest
iterable. This can lead to subtle bugs.
Pass strict=True
to raise a ValueError
if the iterables are of
non-uniform length. Alternatively, if the iterables are deliberately of
different lengths, pass strict=False
to make the intention explicit.
Example
Use instead:
Fix safety
This rule's fix is marked as unsafe. While adding strict=False
preserves
the runtime behavior, it can obscure situations where the iterables are of
unequal length. Ruff prefers to alert users so they can choose the intended
behavior themselves.