Mercurial > cpython-lru_cache-weakref
diff Lib/_abcoll.py @ 43956:fe5b2edffae7
Add ABC ByteString which unifies bytes and bytearray (but not memoryview).
There's no ABC for "PEP 3118 style buffer API objects" because there's no
way to recognize these in Python (apart from trying to use memoryview()
on them).
Note that array.array really should be registered as a MutableSequence
but that would require importing it whenever collections is imported.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 21 Nov 2007 22:26:24 +0000 |
| parents | 0d462d789b18 |
| children | 1f024a95e9d9 |
line wrap: on
line diff
--- a/Lib/_abcoll.py Wed Nov 21 22:24:31 2007 +0000 +++ b/Lib/_abcoll.py Wed Nov 21 22:26:24 2007 +0000 @@ -16,6 +16,7 @@ "Mapping", "MutableMapping", "MappingView", "KeysView", "ItemsView", "ValuesView", "Sequence", "MutableSequence", + "ByteString", ] ### ONE-TRICK PONIES ### @@ -489,8 +490,17 @@ Sequence.register(tuple) Sequence.register(str) -Sequence.register(bytes) -Sequence.register(memoryview) + + +class ByteString(Sequence): + + """This unifies bytes and bytearray. + + XXX Should add all their methods. + """ + +ByteString.register(bytes) +ByteString.register(bytearray) class MutableSequence(Sequence): @@ -531,4 +541,4 @@ self.extend(values) MutableSequence.register(list) -MutableSequence.register(bytes) +MutableSequence.register(bytearray) # Multiply inheriting, see ByteString
