- Python Home
- About
- News
- Documentation
- Downloads
- Community
- Foundation
- Developer's Guide
- Issue Tracker
- Issues
- Summaries
- User
- Administration
- Help
➜
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
| Author | Kentzo |
|---|---|
| Recipients | Kentzo, skrah |
| Date | 2018-12-21.06:18:17 |
| SpamBayes Score | -1.0 |
| Marked as misclassified | Yes |
| Message-id | <1545373099.64.0.788709270274.issue35548@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
|---|
Implementation of memoryview's hashing method [1] imposes the following constraints in order to be hashable (per documentation): > One-dimensional 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()): However it's not clear why original type needs to be hashable given that memoryview deals with 1-dimensional read-only bytes representation of an object. Not only it requires the developer to make an extra copy of C-bytes, but also calls __hash__ of a represented object without using the result other than to detect an error. My particular use case involves a memory view of a readonly numpy's ndarray. My view satisfies the following constraints: >>> print(data.format, data.readonly, data.shape, data.c_contiguous) b True (25,) True But nevertheless the hashing fails because ndarray itself is not hashable. Stefan Krah wrote [2]: > Note that memory_hash() raises an error if the exporter *itself* is not hashable, so it only hashes immutable objects by design. But while __hash__ indeed tells that object is (supposed to be) immutable, there is no requirement for all immutable objects to have __hash__. Both threads I have found ([3], [4]) are quite lengthy and show certain discord in opinions regarding the issue. Perhaps after 6 years since the release of the feature the view on the problem has changed? 1: https://github.com/python/cpython/blob/d1e717588728a23d576c4ead775f7dbd68149696/Objects/memoryobject.c#L2829-L2876 2: https://bugs.python.org/issue15814#msg169510 3: https://bugs.python.org/issue15573 4: https://bugs.python.org/issue15573 |
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2018-12-21 06:18:19 | Kentzo | set | recipients: + Kentzo, skrah |
| 2018-12-21 06:18:19 | Kentzo | set | messageid: <1545373099.64.0.788709270274.issue35548@psf.upfronthosting.co.za> |
| 2018-12-21 06:18:19 | Kentzo | link | issue35548 messages |
| 2018-12-21 06:18:17 | Kentzo | create |
Powered by Roundup Copyright © 1990-2022, Python Software Foundation
Legal Statements
