[issue15814] memoryview: equality-hash invariant

2012-08-30 Thread Dag Sverre Seljebotn

Dag Sverre Seljebotn added the comment:

It is perfectly possible for an object to export memory in a read-only way that 
may still change. Another object may have a writeable view:

x = obj.readonly_view
y = obj.writable_view
obj.move_to_next_image() # changes memory under x, y

So, hashing using tobytes() doesn't make any sense at all to me. A memoryview 
!= its contents.

You could compare memoryviews simply by comparing the Py_buffer structure, but 
that's going to be confusing for a lot of users. I would really prefer 
unhashable (+ if needed a method for comparing contents).

(FWIW, not sure how relevant this is; in NumPy, == does 

In [1]: np.array([1,2,3]) == np.array([1,3,3])
Out[1]: array([ True, False,  True], dtype=bool)

Cython will follow this behaviour for its "typed memory views", which is 
Cython's builting mechanism for PEP 3118 which is not quite the same as CPython 
"memoryview". But I understand that following this behaviour is probably out of 
the question for CPython.)

--
nosy: +Dag.Sverre.Seljebotn

___
Python tracker 
<http://bugs.python.org/issue15814>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15814] memoryview: equality-hash invariant

2012-08-30 Thread Dag Sverre Seljebotn

Dag Sverre Seljebotn added the comment:

OK, I can understand the desire to make memoryviews be bytes-like objects 
(though to my mind, bytes is "frozen" in a very different way...)

If so, and it is deemed worth it, my suggestion is to add a new PyBUF_CONST 
flag to the buffer acquisition in that case (which can not be used together 
with PyBUF_WRITABLE). Given that flag, the exporter guarantees that the 
contents does not change (or fails to give away a buffer).

Perhaps it could be possible for hash() to try to re-acquire a const buffer, so 
that some buffers are hashable (by contents) and others not.

(I really think relying on buffers that are not writeable to be constant is 
dangerous. A readonly memoryview could for instance point straight to the live 
output of a webcam.)

--

___
Python tracker 
<http://bugs.python.org/issue15814>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com