[issue15814] memoryview: equality-hash invariant
Stefan Krah
report at bugs.python.org
Sat Sep 1 16:24:21 CEST 2012
Stefan Krah added the comment:
Martin v. L??wis <report at bugs.python.org> wrote:
> Why be more permissive than necessary? -0 on the committed version;
> it should IMO further restrict it to 1D contiguous byte arrays.
Does "byte arrays" include 'b' and 'c' or just 'B'? I don't see a reason
to allow 'B' but not the others.
I'm +-0 on allowing multi-dimensional arrays, but it would be
odd to restrict hashing to contiguous arrays:
>>> b = b'abcdefhhijkl'
>>> m = memoryview(b)
>>> b[::-1]
b'lkjihhfedcba'
>>> bytes(m[::-1])
b'lkjihhfedcba'
>>> hash(b[::-1]) == hash(m[::-1])
True
My reasoning was: If non-contiguous arrays are allowed (and I think they
should be), why not allow multi-dimensional arrays, too?
The definition hash(m) == hash(m.tobytes()) is pretty straightforward.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15814>
_______________________________________
More information about the Python-bugs-list
mailing list