summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Krah <skrah@bytereef.org>2012-09-01 12:34:45 (GMT)
committerStefan Krah <skrah@bytereef.org>2012-09-01 12:34:45 (GMT)
commit9ecae7a43773eed03a134ee45d79054582e4a35e (patch)
treefa1799d860c88e249d8dc971e9c7c011a9ff0be7
parent2a70535afde79e15c76b1ea50b7055ee0fa25349 (diff)
downloadcpython-9ecae7a43773eed03a134ee45d79054582e4a35e.zip
cpython-9ecae7a43773eed03a134ee45d79054582e4a35e.tar.gz
cpython-9ecae7a43773eed03a134ee45d79054582e4a35e.tar.bz2
Issue #15814: Document planned restrictions for memoryview hashes in 3.3.1.
-rw-r--r--Doc/library/stdtypes.rst22
1 files changed, 7 insertions, 15 deletions
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index e493703..23d7fe1 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -2376,8 +2376,8 @@ copying.
>>> data
bytearray(b'z1spam')
- Memoryviews of hashable (read-only) types are also hashable. The hash
- is defined as ``hash(m) == hash(m.tobytes())``::
+ Memoryviews of hashable (read-only) types with formats 'B', 'b' or 'c'
+ are also hashable. The hash is defined as ``hash(m) == hash(m.tobytes())``::
>>> v = memoryview(b'abcefg')
>>> hash(v) == hash(b'abcefg')
@@ -2387,21 +2387,13 @@ copying.
>>> hash(v[::-2]) == hash(b'abcefg'[::-2])
True
- Hashing of multi-dimensional objects is supported::
-
- >>> buf = bytes(list(range(12)))
- >>> x = memoryview(buf)
- >>> y = x.cast('B', shape=[2,2,3])
- >>> x.tolist()
- [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
- >>> y.tolist()
- [[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]]]
- >>> hash(x) == hash(y) == hash(y.tobytes())
- True
-
.. versionchanged:: 3.3
- Memoryview objects are now hashable.
+ Memoryview objects with formats 'B', 'b' or 'c' are now hashable.
+ .. note::
+ Hashing of memoryviews with formats other than 'B', 'b' or 'c' is
+ possible in version 3.3.0, but will raise an error in 3.3.1 in order
+ to be compatible with the new memoryview equality definition.
:class:`memoryview` has several methods: