You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PyArg_ParseTupleAndKeywords() and non-ASCII keyword names #110815
Most of C strings in the C API are implied to be UTF-8 encoded. PyArg_ParseTupleAndKeywords() mostly works with non-ASCII keyword names as they are UTF-8 encoded. Except one case, when you pass argument by keyword with invalid non-ASCII name to a function that has optional parameter with non-ASCII UTF-8 encoded name. In this case you get a crash in the debug build.
It was caused by combination of f4934ea and a83a6a3 (bpo-28701, #72887). Before these changes you simply got inaccurate or even wrong error message.
Examples:
Parameters: "ä"
Keyword arguments: "ë"
Old behavior: TypeError "'ë' is an invalid keyword argument for this function"
Current behavior: crash
Expected behavior: TypeError "'ë' is an invalid keyword argument for this function"
Parameters: "ä"
Keyword arguments: "ä"
Old behavior: TypeError "invalid keyword argument for this function"
Current behavior: crash
Expected behavior: TypeError "'ä' is an invalid keyword argument for this function"
Parameters: "ä", "ë"
Keyword arguments: "ä", "ë"
Old behavior: TypeError "'ë' is an invalid keyword argument for this function"
Current behavior: crash
Expected behavior: TypeError "'ä' is an invalid keyword argument for this function"
In case 1 the pre-bpo-28701 behavior was correct, in case 2 it was correct but not precise (it failed to find the name of invalid keyword argument), in case 3 it was wrong (it found wrong name). In all cases there is a crash currently.
I am not sure how to classify this issue: as a bug or a new feature. On one hand, it was a regression in 3.7, crash is worse than wrong error message. On other hand, it was not explicitly documented that non-ASCII names are supported, there were no tests, and if it worked, it was only by accident. And it was a long time ago. So, official support of non-ASCII names can be a new feature.
It is an issue with PyArg_ParseTupleAndKeywords(), a C API used for parsing keyword arguments in extension functions. Python defined functions do not use it. Also, it is an issue with argument names, not values. Non-ASCII argument names are forbidden in the core interpreter and the stdlib, but third parties may have reasons to use them.
Activity
pythongh-110815: Support non-ASCII keyword names in PyArg_ParseTupleA…
serhiy-storchaka commentedon Oct 13, 2023
I am not sure how to classify this issue: as a bug or a new feature. On one hand, it was a regression in 3.7, crash is worse than wrong error message. On other hand, it was not explicitly documented that non-ASCII names are supported, there were no tests, and if it worked, it was only by accident. And it was a long time ago. So, official support of non-ASCII names can be a new feature.
pythongh-110815: Support non-ASCII keyword names in PyArg_ParseTupleA…
pythongh-110815: Improve tests for PyArg_ParseTupleAndKeywords()
gh-110815: Improve tests for PyArg_ParseTupleAndKeywords() (GH-110817)
pythongh-110815: Improve tests for PyArg_ParseTupleAndKeywords() (pyt…
[3.12] gh-110815: Improve tests for PyArg_ParseTupleAndKeywords() (GH…
terryjreedy commentedon Oct 13, 2023
Is the issue visible from Python code:
works. If something like this were to crash, I would say definitely a bugfix to be backported.
serhiy-storchaka commentedon Oct 14, 2023
It is an issue with
PyArg_ParseTupleAndKeywords(), a C API used for parsing keyword arguments in extension functions. Python defined functions do not use it. Also, it is an issue with argument names, not values. Non-ASCII argument names are forbidden in the core interpreter and the stdlib, but third parties may have reasons to use them.gh-110815: Support non-ASCII keyword names in PyArg_ParseTupleAndKeyw…
terryjreedy commentedon Oct 15, 2023
Thanks. Makes sense now.
pythongh-110815: Improve tests for PyArg_ParseTupleAndKeywords() (pyt…
pythongh-110815: Support non-ASCII keyword names in PyArg_ParseTupleA…
pythongh-110815: Improve tests for PyArg_ParseTupleAndKeywords() (pyt…
pythongh-110815: Support non-ASCII keyword names in PyArg_ParseTupleA…