-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
io: improve bytes handling #9059
Conversation
This comment has been minimized.
This comment has been minimized.
It isn't that easy, unfortunately:
This is the implemenation: https://github.com/python/cpython/blob/934b25dcc492dcbca4da9d63d0d71dc940fc0375/Modules/_io/textio.c#L284 PyObject *
_PyIncrementalNewlineDecoder_decode(PyObject *myself,
PyObject *input, int final)
{
PyObject *output;
Py_ssize_t output_len;
nldecoder_object *self = (nldecoder_object *) myself;
if (self->decoder == NULL) {
PyErr_SetString(PyExc_ValueError,
"IncrementalNewlineDecoder.__init__ not called");
return NULL;
}
/* decode input (with the eventual \r from a previous pass) */
if (self->decoder != Py_None) {
output = PyObject_CallMethodObjArgs(self->decoder,
&_Py_ID(decode), input, final ? Py_True : Py_False, NULL);
}
else {
output = input;
Py_INCREF(output);
}
if (check_decoded(output) < 0)
return NULL;
/* ... */ So, there are code paths, where only |
Ok, let's go with an easy solution. I don't have any other ideas :( |
This comment has been minimized.
This comment has been minimized.
I'm not sure this is quite right either. The argument gets passed to |
Yes, you are correct. Here's the full sequence:
Then So, I will create a new PR to fix |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
There's an unrelated failure in the CI. |
IncrementalNewlineDecoder.decode
does not supportstr
, but supportsbytearray
andmemoryview
:Buffers: