-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-71679: Enhance bytearray_repr with bytes_repr's logic #104582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Misc/NEWS.d/next/Core and Builtins/2023-05-17-19-54-22.gh-issue-71679.-nD6eA.rst
Outdated
Show resolved
Hide resolved
…e-71679.-nD6eA.rst
Misc/NEWS.d/next/Core and Builtins/2023-05-17-19-54-22.gh-issue-71679.-nD6eA.rst
Outdated
Show resolved
Hide resolved
🤖 New build scheduled with the buildbot fleet by @sunmy2019 for commit bc0270d 🤖 If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
This comment was marked as outdated.
This comment was marked as outdated.
Target to 3.13 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are some problems here.
- We cannot utilize the
PyBytes_Repr
from Python side sincebytes.__repr__
will do checks.
>>> bytes.__repr__(bytearray([1]))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: descriptor '__repr__' requires a 'bytes' object but received a 'bytearray'
-
Although
PyBytes_Repr
is a public API, applying it for not bytes (but supporting buffer protocol) is still weird. As it clearly states, it's a repr of bytes. -
Using the
PyObject_GetBuffer
for bytes slightly hurts the performance of bytes objects.
I think 1 and 2 is the main problem here. I would propose a new function that starts with PyBuffer_*
, maybe PyBuffer_Repr
.
Then, move the implementation to some function foo
.
Then, call this foo
from both PyBuffer_Repr
and PyBytes_Repr
.
@serhiy-storchaka What do you think? |
…e-71679.-nD6eA.rst Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.