Skip to content

Use ReadableBuffer for single-byte codec decode input - #16683

Merged
srittau merged 3 commits into
python:mainfrom
hrithiksaini99:fix/readable-buffer-codec-decode
Nov 3, 2026
Merged

srittau merged 3 commits into
python:mainfrom
hrithiksaini99:fix/readable-buffer-codec-decode

Conversation

@hrithiksaini99

@hrithiksaini99 hrithiksaini99 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Single-byte codecs decode through codecs.charmap_decode, which accepts any buffer, but their stubs only accept bytes. memoryview and bytearray inputs work at runtime (verified on CPython 3.12), so this updates codecs.Codec.decode, the 69 single-byte codec overrides, and punycode's str | ReadableBuffer signature to match.

The base-class change also exposed two dependent third-party stubs that narrow the same method (webencodings, pyserial); those are widened here so the whole tree type-checks.

Verification: tests/mypy_test.py across all 6 Python versions (stdlib and the affected third-party packages), tests/pyright_test.py, and pre-commit. CI stubtest matrix was green after the punycode fix.

Agent: DeepSeek V4.1 Flash (OpenCode).

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

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

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Makes sense.

@srittau
srittau merged commit 001266d into python:main Nov 3, 2026
91 checks passed
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.

2 participants