This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ctypes: Deprecate c_buffer() alias to create_string_buffer()
Type: Stage: resolved
Components: ctypes Versions: Python 3.11
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: lukasz.langa, methane, vstinner
Priority: normal Keywords: patch

Created on 2021-09-01 21:30 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 28114 closed vstinner, 2021-09-01 21:31
PR 28129 merged vstinner, 2021-09-02 16:00
Messages (7)
msg400871 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-09-01 21:30
Since the ctypes module was added to the stdlib (commit babddfca758abe34ff12023f63b18d745fae7ca9 in 2006), ctypes.c_buffer() was an alias to ctypes.create_string_buffer(). The implementation contains a commented deprecation:

def c_buffer(init, size=None):
##    "deprecated, use create_string_buffer instead"
##    import warnings
##    warnings.warn("c_buffer is deprecated, use create_string_buffer instead",
##                  DeprecationWarning, stacklevel=2)
    return create_string_buffer(init, size)

I propose to start to deprecate ctypes.c_buffer(): use ctypes.create_string_buffer() directly.

In older ctypes version, the function was called c_string(): it's still mentioned in the ctypes documentation. This legacy is confusion, and it's time to simplify the API to provide a single function.
msg400900 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2021-09-02 08:19
I'm +0 to this.
Since this alias is not a big maintenance burden, I think we can use deprecation period longer than minimum 2 releases.

In sdist files of the top5000 pypi packages, I found 18 packages using it including false positive (e.g. mypi just have it in pyi file).

```
$ rg -z -w c_buffer *.gz *.zip *.bz2 *.tgz
Binary file Django-3.2.6.tar.gz matches (found "\u{0}" byte around offset 14)
Binary file Wand-0.6.7.tar.gz matches (found "\u{0}" byte around offset 14)
Binary file av-8.0.3.tar.gz matches (found "\u{0}" byte around offset 9)
Binary file eth-hash-0.3.1.tar.gz matches (found "\u{0}" byte around offset 14)
Binary file eth-account-0.5.5.tar.gz matches (found "\u{0}" byte around offset 14)
Binary file eth_abi-2.1.1.tar.gz matches (found "\u{0}" byte around offset 14)
Binary file eth-utils-1.10.0.tar.gz matches (found "\u{0}" byte around offset 14)
Binary file grpcio-1.39.0.tar.gz matches (found "\u{0}" byte around offset 14)
Binary file grpcio-tools-1.39.0.tar.gz matches (found "\u{0}" byte around offset 20)
Binary file hexbytes-0.2.2.tar.gz matches (found "\u{0}" byte around offset 14)
Binary file jedi-0.18.0.tar.gz matches (found "\u{0}" byte around offset 14)
Binary file lxml-4.6.3.tar.gz matches (found "\u{0}" byte around offset 14)
Binary file mypy-0.910.tar.gz matches (found "\u{0}" byte around offset 11)
Binary file os_sys-2.1.4.tar.gz matches (found "\u{0}" byte around offset 13)
Binary file playsound-1.3.0.tar.gz matches (found "\u{0}" byte around offset 14)
Binary file pyarrow-5.0.0.tar.gz matches (found "\u{0}" byte around offset 14)
Binary file pylint-2.10.2.tar.gz matches (found "\u{0}" byte around offset 14)
Binary file pytype-2021.8.24.tar.gz matches (found "\u{0}" byte around offset 17)
```
msg400926 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-02 15:35
-0 I'm not sure it's worth the hassle to remove this. I'd just delete the silly comment that this is supposedly deprecated since at least 2006.

I still get 32,978 results looking at Github Search like this:

https://github.com/search?q=c_buffer+-filename%3Atest_stringptr.py+language%3APython+language%3APython&type=Code

Sure, there's some duplication there, it's not case-sensitive, and some of the c_buffer names might not even be ctypes. But the first few pages are all sensibly looking ctypes results.
msg400928 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-09-02 15:42
> Since this alias is not a big maintenance burden, I think we can use deprecation period longer than minimum 2 releases.

Ok. I modified my PR to only deprecate the alias without planning to remove it. Someone else can decide in at least 2 releases when it will be reasonable to remove the function.
msg400931 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-09-02 16:01
> -0 I'm not sure it's worth the hassle to remove this. I'd just delete the silly comment that this is supposedly deprecated since at least 2006.

Ok, I created PR 28129 for that.
msg400940 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-02 17:02
New changeset a1e15a7a604e6f44cdaf4e106339df62eac5dc9f by Victor Stinner in branch 'main':
bpo-45082: Cleanup ctypes.c_buffer alias (GH-28129)
https://github.com/python/cpython/commit/a1e15a7a604e6f44cdaf4e106339df62eac5dc9f
msg400941 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-02 17:03
Thanks, Victor! ✨ 🍰 ✨
History
Date User Action Args
2022-04-11 14:59:49adminsetgithub: 89245
2021-09-02 17:03:51lukasz.langasetstatus: open -> closed
resolution: rejected
messages: + msg400941

stage: patch review -> resolved
2021-09-02 17:02:07lukasz.langasetmessages: + msg400940
2021-09-02 16:01:24vstinnersetmessages: + msg400931
2021-09-02 16:00:52vstinnersetpull_requests: + pull_request26568
2021-09-02 15:42:54vstinnersetmessages: + msg400928
2021-09-02 15:35:16lukasz.langasetnosy: + lukasz.langa
messages: + msg400926
2021-09-02 08:19:59methanesetnosy: + methane
messages: + msg400900
2021-09-01 21:31:48vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request26555
2021-09-01 21:30:22vstinnercreate