Skip to content

gh-161934: Split TextIOWrapper.write into text and byte helpers - #161991

Open
methane wants to merge 1 commit into
python:mainfrom
methane:codex/textio-write-split
Open

methane wants to merge 1 commit into
python:mainfrom
methane:codex/textio-write-split

Conversation

@methane

@methane methane commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

@cmaloney cmaloney left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 overall; I have a slight preference for keeping the PyObject return because I find that easier to follow than int returns. It may make sense to validate the bytes are actually available/cached in the unicode path.

Comment thread Modules/_io/textio.c
Py_ssize_t bytes_len;
if (b == text) {
if (PyUnicode_Check(b)) {
bytes_len = PyUnicode_GET_LENGTH(b);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Given this function supports text explicitly but requires it has valid cached bytes this branch should check that. Otherwise this will just pass the failure to later in _textiowrapper_writeflush asserts during a flush when we really want to error on a bad argument

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants