bpo-41097: allow io.BufferIO.write() operations when there are buffer views and no buffer resize is required#21792
Open
websurfer5 wants to merge 1 commit intopython:mainfrom
Open
bpo-41097: allow io.BufferIO.write() operations when there are buffer views and no buffer resize is required#21792websurfer5 wants to merge 1 commit intopython:mainfrom
websurfer5 wants to merge 1 commit intopython:mainfrom
Conversation
…o that BytesIO objects can be written when there are one or more buffer views and a resize operation is not required
| @@ -0,0 +1,2 @@ | |||
| :func:`io.BytesIO.write` no longer raises :exc:`BufferError` when one or | |||
Contributor
There was a problem hiding this comment.
It should be meth, not func.
| self.assertEqual(memio.tell(), 1) | ||
| memio.write(bufval3) # should not raise an exception | ||
| self.assertEqual(memio.getvalue(), b'????') | ||
|
|
Contributor
There was a problem hiding this comment.
Please add another space (for PEP 8).
| self.assertRaises(BufferError, memio.write, bufval3) | ||
| # release the buffer view and try forcing a | ||
| # buffer resize | ||
| del buf |
Contributor
There was a problem hiding this comment.
I have doubts about this del.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
io.BytesIO prevents writes when there are buffer view objects. All calls to io.BytesIO.write() raise BufferError with the message "BufferError: Existing exports of data: object cannot be re-sized" even when no resize operation is required. This patch moves the check for existing buffer views from the beginning of the write_bytes() function to the beginning of the resize_buffer() function so that writes can be performed when the output is small enough to fit within the existing buffer.
This change conforms with the behavior implied by the documentation, which merely states that the BytesIO buffer cannot be resized or closed when a view exists. The alternative to this change in behavior is to change the documentation to clarify that write operations are not allowed when there are buffer view objects.
https://bugs.python.org/issue41097