-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add a setlist method to the Headers datastructure #1697
Conversation
The update method added in baa7bdc is meant to replace headers with the mapping passed in. If a MultDict or Headers object is passed in it would replace headers with the final iterated value, rather than all the values iterated over. This could lead to unexpected results, therefore this corrects the functionality to what I think is expected. Consider, h1 = Headers() h1.add("X-Multi", "value") h2 = Headers() h2.add("X-Multi", "newValue") h2.add("X-Multi", "alternativeValue") h1.update(h2) previously `h1.getlist("X-Multi")` would likely equal `["alternativeValue"]` whereas now it equals `["newValue", "alternativeValue"]` which is as you'd expect.
501524c
to
3c4783b
Compare
This doesn't match the behavior of |
Although in this case it probably makes more sense to be replacing rather than extending, it seems like the more likely use case for a collection of headers. If users want the other behavior we can implement |
I agree. (Also I think the test issues are unrelated?) |
They are, that test uses |
Does it make sense for keyword arguments to
I'm going to say yes since passing a dict does that and kwargs is a dict. |
I can update it to do |
setlist removes key if values is empty setlist doesn't copy the values for iteration update uses set instead of `__setitem__` update passes list values in kwargs to setlist add setlistdefault method extend takes kwargs, supports MultiDict add methods to ImmutableHeadersMixin add tests
1a8c134
to
7d8b779
Compare
Pushed a bunch of things I caught while reviewing the related methods and
|
Cool, thanks. |
The update method added in baa7bdc is
meant to replace headers with the mapping passed in. If a MultDict or
Headers object is passed in it would replace headers with the final
iterated value, rather than all the values iterated over. This could
lead to unexpected results, therefore this corrects the functionality
to what I think is expected.
Consider,
previously
h1.getlist("X-Multi")
would likely equal["alternativeValue"]
whereas now it equals["newValue", "alternativeValue"]
which is as you'd expect.