Skip to content

upgrade_pythoncapi.py: Wrong transformations for Py_Is #86

Open
@skirpichev

Description

@skirpichev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions