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

Python MultiDict constructor discards generator content #2

Closed
jchampio opened this issue Jun 3, 2016 · 0 comments · Fixed by #3
Closed

Python MultiDict constructor discards generator content #2

jchampio opened this issue Jun 3, 2016 · 0 comments · Fixed by #3

Comments

@jchampio
Copy link
Contributor

jchampio commented Jun 3, 2016

When using the pure Python implementation, if a MultiDict is constructed with a generator argument:

headers = CIMultiDict(
    (
        k.decode('utf-8', 'surrogateescape'),
        v.decode('utf-8', 'surrogateescape'),
    )
    for k, v in event.headers
)

then the resulting MultiDict will be empty, instead of containing the key/value pairs as expected. This is because the generator is iterated over twice, and the first iteration discards all of the pairs.

jchampio added a commit to jchampio/multidict that referenced this issue Jun 4, 2016
Previously, the MultiDict constructor iterated twice over its argument:
once as a sanity check on its contents, and once again to add those
contents to the dictionary. If a generator was passed as an argument,
the first iteration would drain it, and the resulting dictionary would
be empty.

To fix this, save the contents of the generator in another list. This
fixes aio-libs#2.
asvetlov pushed a commit that referenced this issue Jun 4, 2016
Previously, the MultiDict constructor iterated twice over its argument:
once as a sanity check on its contents, and once again to add those
contents to the dictionary. If a generator was passed as an argument,
the first iteration would drain it, and the resulting dictionary would
be empty.

To fix this, save the contents of the generator in another list. This
fixes #2.
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 a pull request may close this issue.

1 participant