[issue15814] memoryview: equality-hash invariant

Stefan Krah report at bugs.python.org
Fri Aug 31 10:26:49 CEST 2012


Stefan Krah added the comment:

Dag Sverre Seljebotn <report at bugs.python.org> wrote:
> 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

PEP-3118 always means different things to different people. :)

Your distinction between constant, readonly, writable is one way to
interpret things. But looking at the use in the Python source tree,
readonly does mean immutable.

Unfortunately the PEP doesn't specify readonly: Is it the same as
"mount a partition readonly", "readonly CD" or O_RDONLY?

Also, existing practice was that in response to a PyBUF_FULL_RO request
the exporter was free to hand out a writable buffer!

This is now documented and subverts reliable tagging for consumers:

http://docs.python.org/dev/c-api/buffer.html#readonly-format

If any of this is a major inconvenience to NumPy or other users of the
buffer API, perhaps you could open a separate issue.

> (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)

Since afa3dedfee18 we compare memoryviews and any exporter in the same manner
as NumPy, except that the return value is a single boolean. So I think the new
comparison is equivalent to all(a == b) in NumPy.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15814>
_______________________________________


More information about the Python-bugs-list mailing list