amyreese / fissix

backport of lib2to3, with enhancements
Other
45 stars 22 forks source link

Fix: enumerate should not be consuming #48

Open yonran opened 11 months ago

yonran commented 11 months ago

Description

enumerate was accidentally listed in consuming functions, but it only creates an iterator so it is not safe to omit the list() in enumerate(list(d.keys())) unless that iterator itself is called by a consuming function.

This commit makes enumerate an iterator function (like iter) instead of a consuming function (like sorted).

This commit also recursively looks at the parent when d.items(), d.keys(), or d.values() is called from an iterator function to see whether the list() can be omitted. For example, sorted(iter(iter(iter(d.keys())))) does not need `list()

Fixes: #47