Skip to content

Comments

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
websurfer5:fix-issue-41097
Open

bpo-41097: allow io.BufferIO.write() operations when there are buffer views and no buffer resize is required#21792
websurfer5 wants to merge 1 commit intopython:mainfrom
websurfer5:fix-issue-41097

Conversation

@websurfer5
Copy link
Contributor

@websurfer5 websurfer5 commented Aug 9, 2020

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

…o that BytesIO objects can be written when there are one or more buffer views and a resize operation is not required
@websurfer5 websurfer5 changed the title bpo-41097: allow io.BufferIO.write() operations when there are buffer views and no buffer resize is requires bpo-41097: allow io.BufferIO.write() operations when there are buffer views and no buffer resize is required Aug 9, 2020
@@ -0,0 +1,2 @@
:func:`io.BytesIO.write` no longer raises :exc:`BufferError` when one or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be meth, not func.

self.assertEqual(memio.tell(), 1)
memio.write(bufval3) # should not raise an exception
self.assertEqual(memio.getvalue(), b'????')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have doubts about this del.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants