gh-71679: Enhance bytearray_repr with bytes_repr's logic#104582
gh-71679: Enhance bytearray_repr with bytes_repr's logic#104582furkanonder wants to merge 7 commits intopython:mainfrom
Conversation
…e-71679.-nD6eA.rst
|
🤖 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 |
sunmy2019
left a comment
There was a problem hiding this comment.
I think there are some problems here.
- We cannot utilize the
PyBytes_Reprfrom 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_Repris 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_GetBufferfor 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>
serhiy-storchaka
left a comment
There was a problem hiding this comment.
This PR contains only the part of the original patch. It does not change the repr of bytearray.
And it shares the flaw of the original patch -- it does not work with nested classes and classes with non-ASCII names.
See #138181 that solves this problem in other way.
Uh oh!
There was an error while loading. Please reload this page.