gh-70546: Document mmap object's __iter__ behavior that differs from that of bytearray.#140284
gh-70546: Document mmap object's __iter__ behavior that differs from that of bytearray.#140284ztane wants to merge 1 commit intopython:mainfrom
Conversation
548ad51 to
395b9e0
Compare
…tearray. Propose a workaround with a memoryview wrapper.
395b9e0 to
981c4e9
Compare
|
If this PR is merged, I think the referenced issue could be also closed (I cannot do it because it still belongs to a mannequin ;) |
|
I believe this shouldn't skip news, because it is a user-facing update. |
|
@serhiy-storchaka Could you please take a look? |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
It is not only iterating (mmap does not even implement explicit __iter__), but subscribing by an index which returns a bytes object of length 1. And assignment requires a bytes object of length 1, not integer.
To add insult to injury, the code is self-contradictory -- so PyObject_GetItem() returns an integer, but PySequence_GetItem() returns a bytes object of length 1. This is perhaps not visible from Python side.
The documentation should mention all four operations which are different between mmap and other bytes-like objects (bytes, bytearray, array.array, memview): subscribing by an index, assigning by an index, iteration and the containment check.
#70546 reports that mmap object
__iter__behavior dffers from that ofbytearray. This pr adds a notice that states thatmmapobjects have__iter__that differs from that ofbytearrays and that you can wrap the object inside amemoryviewto work around the difference.