Skip to content

Commit

Permalink
Clarify that the Headers class is a Sequence
Browse files Browse the repository at this point in the history
This is both in the docs (via the changelog) and by inheriting from
the Sequence ABC. As the Sequence ABC has a __iter__ method another is
not required.
  • Loading branch information
pgjones committed May 16, 2021
1 parent 82d5e46 commit a022a58
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
7 changes: 2 additions & 5 deletions h11/_headers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from collections.abc import Sequence

from ._abnf import field_name, field_value
from ._util import bytesify, LocalProtocolError, validate
Expand Down Expand Up @@ -62,7 +63,7 @@
_field_value_re = re.compile(field_value.encode("ascii"))


class Headers:
class Headers(Sequence):
"""
A list-like interface that allows iterating over headers as byte-pairs
of (lowercased-name, value).
Expand Down Expand Up @@ -92,10 +93,6 @@ class Headers:
def __init__(self, full_items):
self._full_items = full_items

def __iter__(self):
for _, name, value in self._full_items:
yield name, value

def __bool__(self):
return bool(self._full_items)

Expand Down
3 changes: 3 additions & 0 deletions newsfragments/112.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Clarify that the Headers class is a Sequence and inherit from the
collections Sequence abstract base class to also indicate this (and
gain the mixin methods). See also #104.

0 comments on commit a022a58

Please sign in to comment.