Skip to content

Conversation

@cmaloney
Copy link
Contributor

@cmaloney cmaloney commented Nov 13, 2025

If the underlying I/O class keeps a reference to the memory raise BufferError.

Uses gh-139871 to implement.

--
If want to maintain closer compatibility when a BufferError occurs can fall back to a copy (copying is as safe as the original code). I have a slight preference to erroring as I think keeping a reference to the memory is uncommon (and probably unintended).

If the underlying I/O class keeps a reference to the memory raise BufferError.
}
return res;
}
res = PyObject_CallMethod(b, "take_bytes", NULL);
Copy link
Contributor Author

@cmaloney cmaloney Nov 13, 2025

Choose a reason for hiding this comment

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

@vstinner : Not sure how common this "resize/discard then take_bytes" is going to be; might make sense to change to take_bytes(n=None, /, *, discard=False)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for now planning to keep that in back pocket until need many ways (ba.resize(n) or del ba[:n] gives the same capability)

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Can you also update RawIOBase.read() in the _pyio module?

@cmaloney
Copy link
Contributor Author

Have that in #141539 which does all the cases .take_bytes can be used in _pyio :).

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.

2 participants