Skip to content

[ssl] Return byte counts from buffered reads - #16835

Merged
srittau merged 1 commit into
python:mainfrom
krish-goradia:fix/ssl-buffered-read-return
Nov 16, 2026
Merged

srittau merged 1 commit into
python:mainfrom
krish-goradia:fix/ssl-buffered-read-return

Conversation

@krish-goradia

Copy link
Copy Markdown
Contributor

Overload SSLObject.read() and SSLSocket.read() to return int when a writable buffer is supplied and bytes when it is omitted or None, matching the documented behavior and CPython implementation.

Currently, valid buffered reads such as count: int = ssl_object.read(buffer=bytearray(1024)) are rejected, while calling .decode() on that integer result is accepted.

Agent used: Codex.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/util/ssltransport.py:211: error: Argument 1 to "_ssl_io_loop" of "SSLTransport" has incompatible type overloaded function; expected "Callable[[int, bytearray | None], bytes]"  [arg-type]

@srittau
srittau merged commit 7ec374f into python:main Nov 16, 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.

2 participants