python / python/pythoncapi-compat
upgrade_pythoncapi.py: Wrong transformations for Py_Is
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 110
- Forks
- 39
- Avg merge
- 8m
- Merged PRs (30d)
- 2
Description
Consider an example:
if (((PyObject*)obj)->data == Py_None) {
111;
}
if (Py_None == ((PyObject*)obj)->data) {
111;
}
After upgrade_pythoncapi.py I got:
#include "pythoncapi_compat.h"
if (((PyObject*)obj)->Py_IsNone(data)) {
111;
}
if (Py_None == ((PyObject*)obj)->data) {
111;
}
Real world example:
https://github.com/aleaxit/gmpy/blob/eb8dfcbd84abcfcb36b4adcb0d5c6d050731dd75/src/gmpy2_xmpz_misc.c#L237
I'm not sure if this is a bug. This kind of issues is not easy to avoid, using regexps for code transformations. Have you considered to use something like the pycparser?
Thanks for the project.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with upgrade_pythoncapi.py and reproduce both C examples from the issue, then compare the output with the referenced gmpy2_xmpz_misc.c case. Check whether the transformation handles both operand orders without corrupting member access; done means valid C is produced with the intended Py_IsNone transformation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100