C2PY_RENAME

The C2PY_RENAME annotation can be used to give a wrapped function or class a different name in the Python bindings.

C++ code

#include "c2py/c2py.hpp"

// We want to rename f to g in the Python bindings.
C2PY_RENAME(g) int f(int x) { return x * 2; }

Usage in Python

After generating the extension module, we can use it in Python:

>>> from c2py_rename import *
>>> g(5)
10
>>> f(5)
Traceback (most recent call last):
...
NameError: name 'f' is not defined

The function f has been renamed to g as instructed.