Skip to content

B905 recommends unnecessary strict for less than two iterables #20997

@dscorbett

Description

@dscorbett

Summary

zip-without-explicit-strict (B905) reports diagnostics for zip calls with less than two positional arguments, which is unnecessary. strict can only make a difference when there are two or more positional arguments, or any starred positional arguments. Compare map-without-explicit-strict (B912), which is only triggered when there are two or more positional arguments. Example:

$ cat >b905.py <<'# EOF'
print(tuple(zip()))
print(tuple(zip("abc")))

print(tuple(map(lambda x: x, "abc")))
# EOF

$ python b905.py
()
(('a',), ('b',), ('c',))
('a', 'b', 'c')

$ ruff --isolated check b905.py --select B905,B912 --target-version py314 --preview --unsafe-fixes --diff
--- b905.py
+++ b905.py
@@ -1,4 +1,4 @@
-print(tuple(zip()))
-print(tuple(zip("abc")))
+print(tuple(zip(strict=False)))
+print(tuple(zip("abc", strict=False)))
 
 print(tuple(map(lambda x: x, "abc")))

Would fix 2 errors.

Version

ruff 0.14.1 (2bffef5 2025-10-16)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions