Skip to content
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

[C API] Add PyBytes_Join() function #121645

Closed
vstinner opened this issue Jul 12, 2024 · 5 comments
Closed

[C API] Add PyBytes_Join() function #121645

vstinner opened this issue Jul 12, 2024 · 5 comments
Labels
topic-C-API type-feature A feature request or enhancement

Comments

@vstinner
Copy link
Member

vstinner commented Jul 12, 2024

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 vstinner added type-feature A feature request or enhancement topic-C-API labels Jul 12, 2024
vstinner added a commit to vstinner/cpython that referenced this issue Jul 12, 2024
vstinner added a commit to vstinner/cpython that referenced this issue Jul 12, 2024
@vstinner
Copy link
Member Author

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)

@vstinner
Copy link
Member Author

mypyc uses it

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

@ZeroIntensity
Copy link
Member

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

@vstinner
Copy link
Member Author

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 capi-workgroup/api-evolution#36.

Instead, I created #121710: [C API] Add PyBytesWriter API.

vstinner added a commit to vstinner/cpython that referenced this issue Aug 27, 2024
* Replace _PyBytes_Join() with PyBytes_Join().
* Keep _PyBytes_Join() as an alias to PyBytes_Join().
vstinner added a commit that referenced this issue Aug 30, 2024
* Replace _PyBytes_Join() with PyBytes_Join().
* Keep _PyBytes_Join() as an alias to PyBytes_Join().
@vstinner
Copy link
Member Author

Implemented by the change 3d60dfb.

vstinner added a commit to vstinner/cpython that referenced this issue Sep 6, 2024
hauntsaninja pushed a commit to python/mypy that referenced this issue Oct 14, 2024
Use functions added for Python 3.14
* `PyBytes_Join` added in
python/cpython#121645
* `PyUnicode_Equal` added in
python/cpython#124502
cdce8p added a commit to cdce8p/mypy that referenced this issue Oct 14, 2024
Use functions added for Python 3.14
* `PyBytes_Join` added in
python/cpython#121645
* `PyUnicode_Equal` added in
python/cpython#124502
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-C-API type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants