Skip to content

Windows cpXXX codecs: StreamReader raises TypeError (decode() missing 'final') #158980

Description

@sricursion

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    3.14bugs and security fixes
    3.15bugs and security fixes
    3.16new features, bugs and security fixes
    on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15bugs and security fixes3.16new features, bugs and security fixesOS-windowstype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions