Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: enumerate should not be consuming #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yonran
Copy link

@yonran yonran commented Oct 11, 2023

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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix_dict does not wrap enumerate(d.items()) in a list
1 participant