Bug report
Bug description:
Since 3.14 (gh-123803), the cpXXX codecs for the Windows code pages that have no module of their own in encodings are provided by encodings._win_cp_codecs. Their stream reader cannot read anything:
import codecs, io
text = 'привет'
reader = codecs.getreader('cp20866')(io.BytesIO(text.encode('cp20866')))
print(reader.read() == text)
Output:
Traceback (most recent call last):
File "repro.py", line 5, in <module>
print(reader.read() == text)
~~~~~~~~~~~^^
File ".../Lib/codecs.py", line 512, in read
newchars, decodedbytes = self.decode(data, self.errors)
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
TypeError: create_win32_code_page_codec.<locals>.StreamReader.decode() missing 1 required positional argument: 'final'
Expected output: True.
readline() and codecs.StreamReaderWriter.read() fail in the same way. codecs.iterdecode() and io.TextIOWrapper work, because they use the incremental decoder.
codecs.StreamReader.read() calls self.decode(data, self.errors), but StreamReader.decode() in Lib/encodings/_win_cp_codecs.py is defined as decode(self, input, errors, final), so final is required. It should be optional and default to False (as for encodings.mbcs), so that an incomplete multibyte sequence is kept until the next read.
CPython versions tested on:
CPython main branch (the 3.14 and 3.15 branches contain the same code)
Operating systems tested on:
Windows
Linked PRs
Bug report
Bug description:
Since 3.14 (gh-123803), the
cpXXXcodecs for the Windows code pages that have no module of their own inencodingsare provided byencodings._win_cp_codecs. Their stream reader cannot read anything:Output:
Expected output:
True.readline()andcodecs.StreamReaderWriter.read()fail in the same way.codecs.iterdecode()andio.TextIOWrapperwork, because they use the incremental decoder.codecs.StreamReader.read()callsself.decode(data, self.errors), butStreamReader.decode()inLib/encodings/_win_cp_codecs.pyis defined asdecode(self, input, errors, final), sofinalis required. It should be optional and default toFalse(as forencodings.mbcs), so that an incomplete multibyte sequence is kept until the next read.CPython versions tested on:
CPython main branch (the 3.14 and 3.15 branches contain the same code)
Operating systems tested on:
Windows
Linked PRs