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: “unmatched paren” for space before parenthesis in Py_BuildValue
Type: Stage: patch review
Components: C API Versions: Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Wrzlprmft, ZackerySpytz
Priority: normal Keywords: patch

Created on 2020-04-17 08:54 by Wrzlprmft, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
foo.c Wrzlprmft, 2020-04-17 08:54 Minimal Python C Extension showing the bug
Pull Requests
URL Status Linked Edit
PR 21158 open ZackerySpytz, 2020-06-25 15:53
Messages (1)
msg366647 - (view) Author: Gerrit Ansmann (Wrzlprmft) Date: 2020-04-17 08:54
According to the C-API documentation¹ for `Py_BuildValue`:

> The characters space, tab, colon and comma are ignored in format strings (but not within format units such as s#). This can be used to make long format strings a tad more readable.

However format strings such as `"(d )"` cause the error:

> Unmatched paren in format

By contrast `"( d)"` and `"(d d)"` cause no problems. I therefore assume that tuples are not considered “format units” in the sense of the above quote and this is a bug. Alternatively, the documentation needs clarification.

I could reproduce this problem with Python 3.7 and 3.8. I did not try other versions.

Appended is a minimal C extension exhibiting the problem. I compile and run with:

gcc -fPIC -I/usr/include/python3.8 -c foo.c -o foo.o
gcc -shared foo.o -o foo.so
python3.8 -c "import foo; foo.bar()"

----

¹ https://docs.python.org/3/c-api/arg.html
History
Date User Action Args
2022-04-11 14:59:29adminsetgithub: 84489
2020-06-25 15:53:09ZackerySpytzsetkeywords: + patch
nosy: + ZackerySpytz

pull_requests: + pull_request20318
stage: patch review
2020-04-17 08:54:27Wrzlprmftcreate