diff options
author | Guido van Rossum <guido@python.org> | 2007-11-21 22:26:24 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-11-21 22:26:24 +0000 |
commit | 7eb013bb7b4606780cb588818074a507272aab06 (patch) | |
tree | 0b2c5ffc61139906b53bccee69a37893303408c7 /Lib/_abcoll.py | |
parent | 488a954fa5667a3eb8e7350c1404e70dfe4097be (diff) | |
download | cpython-7eb013bb7b4606780cb588818074a507272aab06.tar.gz |
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.
Diffstat (limited to 'Lib/_abcoll.py')
-rw-r--r-- | Lib/_abcoll.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Lib/_abcoll.py b/Lib/_abcoll.py index ec3e2f838c..6363de9bb7 100644 --- a/Lib/_abcoll.py +++ b/Lib/_abcoll.py @@ -16,6 +16,7 @@ __all__ = ["Hashable", "Iterable", "Iterator", "Mapping", "MutableMapping", "MappingView", "KeysView", "ItemsView", "ValuesView", "Sequence", "MutableSequence", + "ByteString", ] ### ONE-TRICK PONIES ### @@ -489,8 +490,17 @@ class Sequence(metaclass=ABCMeta): 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 @@ class MutableSequence(Sequence): self.extend(values) MutableSequence.register(list) -MutableSequence.register(bytes) +MutableSequence.register(bytearray) # Multiply inheriting, see ByteString |