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: PyArg_ParseTupleAndKeywords doesn't take const char *keywords[]
Type: enhancement Stage:
Components: Extension Modules Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: h.venev, josh.r, methane, serhiy.storchaka
Priority: normal Keywords:

Created on 2014-03-21 16:45 by h.venev, last changed 2022-04-11 14:58 by admin.

Messages (4)
msg214388 - (view) Author: Hristo Venev (h.venev) * Date: 2014-03-21 16:45
This really annoys me. I have to store the literals in char[] and then make a char*[] from them. It would be better if a simple array of string literals could be used. It would also require less data space because string literals could be merged by the compiler.

I don't know why PyArg_ParseTupleAndKeywords would ever modify the keywords array so it makes absolutely no sense to me for the array not to be const char*[].

In all cases I have seen PyArg_ParseTupleAndKeywords being used string literals were converted to char* (dropping const) which is far far worse than inefficient code.
msg214857 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2014-03-25 22:02
This has come up before. Links to additional info:

https://mail.python.org/pipermail/python-dev/2006-February/060689.html

http://bugs.python.org/issue1772673
msg320945 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2018-07-03 09:06
I think we can't fix this until Python 4.
May I close this issue as "won't fix" for now?

Or can we add "Python 4" keyword to list backward incompatible changes we want to do in the future?
msg320952 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-07-03 09:45
We can't change this API because this would break virtually all user code.

But we can introduce a macro like PY_SSIZE_T_CLEAN. If it is defined before including Python.h, PyArg_ParseTupleAndKeywords() will take an array of const strings. This will help for compatibility with C++.
History
Date User Action Args
2022-04-11 14:58:00adminsetgithub: 65210
2021-06-12 07:02:12serhiy.storchakalinkissue44401 superseder
2018-07-03 09:45:24serhiy.storchakasettype: resource usage -> enhancement

messages: + msg320952
nosy: + serhiy.storchaka
2018-07-03 09:06:58methanesetnosy: + methane

messages: + msg320945
versions: + Python 3.8, - Python 3.4
2014-03-25 22:02:19josh.rsetnosy: + josh.r
messages: + msg214857
2014-03-21 16:45:16h.venevcreate