Skip to content

B905 and B912 fixes should be unsafe #20694

@dscorbett

Description

@dscorbett

Summary

The fixes for zip-without-explicit-strict (B905) and map-without-explicit-strict (B912) should be marked unsafe by the same reasoning as in this comment:

The issue isn't that our fix would change behavior but that we could silently preserve the wrong behavior. Instead we should alert the user to the issue so that they can decide what it's supposed to say.

Example:

$ cat >b9.py <<'# EOF'
print(list(zip("ab", "123")))
print(list(map(lambda x, y: y + x, "ab", "123")))
# EOF

$ python b9.py
[('a', '1'), ('b', '2')]
['1a', '2b']

$ ruff --isolated check b9.py --select B905,B912 --preview --target-version py314 --fix
Found 2 errors (2 fixed, 0 remaining).

$ cat b9.py
print(list(zip("ab", "123", strict=False)))
print(list(map(lambda x, y: y + x, "ab", "123", strict=False)))

$ python3.14 b9.py
[('a', '1'), ('b', '2')]
['1a', '2b']

Version

ruff 0.13.3 (188c0dc 2025-10-02)

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixesRelated to suggested fixes for violations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions