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

flatten treats iterable-once objects not carefully enough #583

Closed
aananko opened this issue Jun 7, 2021 · 2 comments
Closed

flatten treats iterable-once objects not carefully enough #583

aananko opened this issue Jun 7, 2021 · 2 comments

Comments

@aananko
Copy link

aananko commented Jun 7, 2021

>>> (range(2) for _ in range(2)) |> flatten |> list
[]

but

>>> (range(2) for _ in range(2)) |> flatten |> iter |> list
[0, 1, 0, 1]

Looks like list() constructor does notice __len__ and calls it first, and flatten.__len__ consumes the generator.

@evhub evhub added the oversight label Jun 7, 2021
@evhub evhub added this to the v1.6.0 milestone Jun 7, 2021
@evhub
Copy link
Owner

evhub commented Jun 7, 2021

Good catch! I thought I added a test for that case, but I guess not.

evhub added a commit that referenced this issue Jun 7, 2021
@evhub evhub added the resolved label Jun 7, 2021
@evhub evhub closed this as completed Jun 7, 2021
@aananko
Copy link
Author

aananko commented Jun 8, 2021

Your response time is incredible, thanks!

evhub added a commit that referenced this issue Nov 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants