cpython
cpython copied to clipboard
[C API] Add PyBytes_Join() function
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
- gh-121646
mypyc uses it.
A code search on PyPI top 7,500 projects found 6 projects using the private _PyBytes_Join() function:
- Cython (3.0.9)
- dbnd (1.0.22.9)
- dulwich (0.21.7)
- mod_wsgi (5.0.0)
- mpi4py (3.1.5)
- mypy (1.9.0)
mypyc uses it
Sorry, I forgot to add a reference to the mypy issue: issue gh-121489.
Additionally, many repositories use _PyBytes_Resize as well. Perhaps that's something that should go public?
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.
Implemented by the change https://github.com/python/cpython/commit/3d60dfbe1755e00ab20d0ee81281886be77ad5da.
Dear @vstinner,
I have an issue during my Python wheel generation on Linux, Python 3.13:
../numpy/_core/src/common/pythoncapi-compat/pythoncapi_compat.h: In function ‘PyObject* PyBytes_Join(PyObject*, PyObject*)’:
../numpy/_core/src/common/pythoncapi-compat/pythoncapi_compat.h:1607:12: error: ‘_PyBytes_Join’ was not declared in this scope; did you mean ‘PyBytes_Join’?
My code has numpy dependency and it uses pybind11 C++ library. I would like then to generate a wheel for it.
Could it be due to this renaming? There is a check here but it checks only Python 3.14, and not 3.13:
I see there is a backward compatibility was assumed
As you can see it doesn't work in my case.
The whole log is here https://pastebin.com/Am07UcZg I have this issue only for Python 3.13, only on Linux (docker image python:3.13). I tried to just install numpy and that works there. Looks like for my wheel creation, it does something else which fails. And there is no such an issue on other Python versions (3.12 or 3.14) and Windows (Python 3.10-3.14).
I will appreciate you help.
Best, ilshat
@i-l-s-h-a-t: Interesting bug. It's unrelated to Python, so can you please open an issue at https://github.com/python/pythoncapi-compat/issues? Please include commands on how to reproduce your issue.
@i-l-s-h-a-t: Interesting bug. It's unrelated to Python, so can you please open an issue at https://github.com/python/pythoncapi-compat/issues? Please include commands on how to reproduce your issue.
@vstinner Thank you for your reply. I created an issue there. Although I could not reproduce the issue locally which appears in gitlab CI/CD.