GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||
GeezerVison is showing github.com — io: improve bytes handling by sobolevn · Pull Request #9059 · python/typeshed Conversation
Member
>>> import codecs, io >>> dec = codecs.getincrementaldecoder('utf8')() >>> d = io.IncrementalNewlineDecoder(dec, translate=True) >>> d.decode('str') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/codecs.py", line 321, in decode data = self.buffer + input TypeError: can't concat str to bytes Buffers: >>> d.decode(bytearray(b'\r')) '\n' >>> d.decode(memoryview(b'\r')) '\n' >>> d.decode(b'\r') '\n'
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
This comment has been minimized.
|
There was an error while loading. Please reload this page.
|
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ok, let's go with an easy solution. I don't have any other ideas :( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm not sure this is quite right either. The argument gets passed to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yes, you are correct. Here's the full sequence:
Then So, I will create a new PR to fix |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
There's an unrelated failure in the CI. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.