Skip to content

Mark io.Reader and io.Writer as runtime-checkable - #16888

Merged
JelleZijlstra merged 1 commit into
python:mainfrom
jelle-openai:jelle/codex/runtime-checkable-io
Nov 21, 2026
Merged

JelleZijlstra merged 1 commit into
python:mainfrom
jelle-openai:jelle/codex/runtime-checkable-io

Conversation

@jelle-openai

Copy link
Copy Markdown
Contributor

Mark io.Reader and io.Writer as @runtime_checkable so type checkers accept them in isinstance, issubclass, and class patterns.

CPython implements both as ABCs with __subclasshook__ methods that check for read and write, respectively. The typing_extensions stubs already use @runtime_checkable for the backports on Python < 3.14.

Prepared with Codex.

@github-actions

Copy link
Copy Markdown
Contributor

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

@JelleZijlstra

Copy link
Copy Markdown
Member

I also had Codex look for other similar classes (ABC at runtime, non-runtime-checkable protocol in typeshed) and it didn't find any others.

@JelleZijlstra
JelleZijlstra merged commit b86143c into python:main Nov 21, 2026
88 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.

3 participants