h11 icon indicating copy to clipboard operation
h11 copied to clipboard

regression: event header can't be copied with normal Python syntax.

Open kdart-brt opened this issue 5 years ago • 7 comments

I have been using h11 for a while now. In my code, I made a copy of the headers like this:

headers = ev.headers[:]

That is the normal way to copy a list (headers was a list).

Now, after an update, it does this: ValueError: too many values to unpack (expected 3)

in debugger, the same: 1:Debug:1/2> ev.headers[:] *** ValueError: too many values to unpack (expected 3)

Something changed in the headers attrbibute. It also does not have a copy method. 1:Debug:1/2> ev.headers.copy() *** AttributeError: 'Headers' object has no attribute 'copy'

kdart-brt avatar Oct 12 '20 17:10 kdart-brt

@kdart-brt The way headers work has changed with https://github.com/python-hyper/h11/pull/104 which was released recently

pquentin avatar Oct 13 '20 07:10 pquentin

Right, so the intent was not to cause any regressions in how we approached #104, but that's obviously not quite been the case here, since you've found a wrinkle.

The change here is that the requirement in #104, of "allow h11 to expose the original header casing" meant that we've needed to change headers from a list to a sequence-like interface in the 0.11 release.

There's two options for us here:

  • Issue an amendment in https://h11.readthedocs.io/en/latest/changes.html#v0-11-0-2020-10-05 to make that explicit.
  • Change the Headers data structure so that we're ensuring it has a fully list-like interface, rather than simple a sequence interface.

Of those two I'd probably tend towards the first.

From a user POV that'd mean using the following if you want a list-copy of the structure...

headers = list(ev.headers)

lovelydinosaur avatar Oct 13 '20 08:10 lovelydinosaur

That alternate list constructor works. So, whatever you do is fine by me.

kdart-brt avatar Oct 14 '20 13:10 kdart-brt

👍 on the simple amendment

pquentin avatar Oct 14 '20 16:10 pquentin

BTW, thanks for the help.

kdart-brt avatar Oct 19 '20 18:10 kdart-brt

You're very welcome. 💛

lovelydinosaur avatar Oct 19 '20 19:10 lovelydinosaur

Does #125 help this?

pgjones avatar Dec 27 '20 14:12 pgjones

Does https://github.com/python-hyper/h11/pull/125 help this?

Yes.

lovelydinosaur avatar Jul 31 '23 16:07 lovelydinosaur