Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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.
@yonran yonran force-pushed the fix-enumerate-nonconsuming branch from c34a85b to 918f092 Compare October 11, 2023 09:20
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