Repository navigation
Accept Any in bytes and bytearray percent-formatting - #16529
Merged
Merged
Conversation
The format string chooses the conversion, so an int is valid for b%d and an arbitrary object is valid for %a and %r. The parameter type now matches str.__mod__. AI-assisted (Cursor).
This comment has been minimized.
This comment has been minimized.
Contributor
|
The title should be "Accept |
object in bytes and bytearray percent-formatting
Contributor
Author
|
Updated the title. |
srittau
requested changes
Oct 14, 2026
| def __rmul__(self, value: SupportsIndex, /) -> bytes: ... | ||
| def __mod__(self, value: Buffer | SupportsBytes | tuple[Buffer | SupportsBytes, ...], /) -> bytes: ... | ||
| # The format string chooses the conversion, including numbers and %a/%r (PEP 461). | ||
| def __mod__(self, value: object, /) -> bytes: ... |
Collaborator
There was a problem hiding this comment.
We should use Any as argument (as it was before), since not literally every value is supported in every situation. The comment also makes sense as documentation for the Any (which we require nowadays).
Same below.
Contributor
Author
There was a problem hiding this comment.
Updated both arguments to Any and kept the comment.
Not every value works with every format string, so the argument stays Any and the comment stays with it. AI-assisted (Cursor).
object in bytes and bytearray percent-formattingAny in bytes and bytearray percent-formatting
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
srittau
approved these changes
Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #16528.
bytes.__mod__andbytearray.__mod__takeAny. The format string chooses the conversion, and not every value works with every format, so this is notobject.https://docs.python.org/3/library/stdtypes.html#printf-style-bytes-formatting
https://peps.python.org/pep-0461/
Agent: Cursor (Grok 4.7)
Cherith reviewed this diff and confirmed it with the person who helped draft it.