python / cpython

The Python programming language
https://www.python.org
Other
63.31k stars 30.31k forks source link

[C API] Add PyBytes_Join() function #121645

Closed vstinner closed 2 months ago

vstinner commented 3 months ago

Feature or enhancement

Python 3.13 alpha 1 removed the private _PyBytes_Join(sep, iterable) function which calls sep.join(iterable).

mypyc uses it. Since we already have PyUnicode_Join(sep, iterable), I propose to add a new PyBytes_Join() function.

In practice, it's just about renaming _PyBytes_Join() to PyBytes_Join().

Linked PRs

vstinner commented 3 months ago

mypyc uses it.

A code search on PyPI top 7,500 projects found 6 projects using the private _PyBytes_Join() function:

vstinner commented 3 months ago

mypyc uses it

Sorry, I forgot to add a reference to the mypy issue: issue gh-121489.

ZeroIntensity commented 3 months ago

Additionally, many repositories use _PyBytes_Resize as well. Perhaps that's something that should go public?

vstinner commented 3 months ago

Additionally, many repositories use _PyBytes_Resize as well. Perhaps that's something that should go public?

IMO _PyBytes_Resize() is a bad pattern, it uses a bytes object which is incomplete/inconsistent: see https://github.com/capi-workgroup/api-evolution/issues/36.

Instead, I created https://github.com/python/cpython/issues/121710: [C API] Add PyBytesWriter API.

vstinner commented 2 months ago

Implemented by the change https://github.com/python/cpython/commit/3d60dfbe1755e00ab20d0ee81281886be77ad5da.