Skip to content

RUF058 fix does not check if map is shadowed #15786

@dscorbett

Description

@dscorbett

Description

The fix for starmap-zip (RUF058) in Ruff 0.9.3 inserts map without checking that it is the built-in map. If map is shadowed, the fix changes the program’s behavior.

$ cat >ruf058.py <<'# EOF'
from itertools import starmap
map = {}
for _ in starmap(print, zip("A", "12")):
    pass
# EOF

$ python ruf058.py
A 1

$ ruff --isolated check --preview --select RUF058 ruf058.py --fix
Found 1 error (1 fixed, 0 remaining).

$ cat ruf058.py
from itertools import starmap
map = {}
for _ in map(print, "A", "12"):
    pass

$ python ruf058.py
Traceback (most recent call last):
  File "ruf058.py", line 3, in <module>
    for _ in map(print, "A", "12"):
             ^^^^^^^^^^^^^^^^^^^^^
TypeError: 'dict' object is not callable

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions