Message169515
Am 31.08.12 06:14, schrieb Stefan Behnel:
> To add on Dag's comments, this essentially means that any caching of
> the hash value is dangerous
Stefan Krah is right here: the proper test (which is already
implemented) is whether the underlying object is hashable; this
is a sufficient test.
Caching of the hash is always correct, or else the hash function
is incorrect: a hash of an object must not change. If it would
change, you couldn't find the key anymore in a dictionary.
> unless it can be assured that the
> underlying buffer definitely has not changed in the meantime. There
> is no way for users to explicitly tell a memoryview to rehash itself,
> so putting it into one dict, then modifying the content, then putting
> it into another is a perfectly reasonable use case for users,
No, it's not:
d = {}
o = some_object
m = memoryview(o)
d[m] = -1
o.modify() # so that hash(m) changes
print(d[m]) # keyerror, even though m in d.keys()
> As far as I can see it, any "obvious" fix for this creates a whole
> bath tub full of worms: updating views transitively, adding new APIs,
> supporting new buffer parameters, ...
So above (in this thread): the easiest fix is to just drop hashing
support for memoryview objects. This can be extended in steps:
- support hashing if the underlying object is bytes
- support hashing if the shape is 1D "B", and the underlying object
is hashable
- support hashing if the exporter has somehow promised to not modify
the memory |
|
Date |
User |
Action |
Args |
2012-08-31 10:01:43 | loewis | set | recipients:
+ loewis, georg.brandl, mark.dickinson, ncoghlan, belopolsky, pitrou, scoder, vstinner, christian.heimes, Arfrever, skrah, meador.inge, Dag.Sverre.Seljebotn |
2012-08-31 10:01:43 | loewis | link | issue15814 messages |
2012-08-31 10:01:42 | loewis | create | |
|