Skip to content

Allow keyword errors for UTF-8 decoders - #16447

Open
jw9829 wants to merge 4 commits into
python:mainfrom
jw9829:fix-codecs-decoder-keyword-errors-repost
Open

jw9829 wants to merge 4 commits into
python:mainfrom
jw9829:fix-codecs-decoder-keyword-errors-repost

Conversation

@jw9829

@jw9829 jw9829 commented Sep 27, 2026 •

Copy link
Copy Markdown

Fixes #16441.

The UTF-8 decoder returned by codecs.lookup() accepts errors= as a keyword. Other codecs keep a positional-only signature because some reject keyword arguments.

@github-actions

This comment has been minimized.

Comment thread stdlib/codecs.pyi Outdated
@type_check_only
class _Decoder(Protocol):
def __call__(self, input: ReadableBuffer, errors: str = ..., /) -> tuple[str, int]: ... # signature of Codec().decode
def __call__(self, input: ReadableBuffer, /, errors: str = ...) -> tuple[str, int]: ... # signature of Codec().decode

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not correct for all codecs:

>>> codecs.lookup("ascii").decode(b"abc", errors="replace")
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    codecs.lookup("ascii").decode(b"abc", errors="replace")
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: _codecs.ascii_decode() takes no keyword arguments

@jw9829 jw9829 changed the title Allow keyword errors for codec decoders Allow keyword errors for UTF-8 decoders Sep 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Comment thread stdlib/codecs.pyi

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

false alarm on decode call

2 participants