In the course of some work I am currently involved in I needed to understand better the content of the .py file which is generated when wrapping C++ using Swig. This is in the context of an existing system (which I did not write) which adds some custom Python that manipulates the content of the globals()
in the module. While trying to understand this I realised I did not even understand the 'normal' Swig generated code.
Suppose, for example, we are creating a module, MyModule, and in this we wrap a C++ function void f()
. The following will appear in the Swig-generated Python file MyModule.py:
def f():
return _MyModule.f()
f = _MyModule.f
My question is: what is the point of the first two lines of the above? The entry for 'f' that is added to MyModule's globals()
by those first two lines is immediately overwritten by the third line, which I believe is essentially equivalent to the preceding def f()
.
Am I missing something?