Search code examples
python-3.xpython-c-api

What type of reference does PyModule_GetFilenameObject return?


PyModule_GetFilename was apparently deprecated in version 3.2, with PyModule_GetFilenameObject being the suggested replacement. PyModule_GetFilenameObject returns a PyObject*, but the Python 3 C API documentation doesn't specify whether the returned object is a new reference or a borrowed reference. What kind of reference is returned?


Solution

  • After looking at the source, PyModule_GetFilenameObject calls Py_INCREF on the PyObject* it returns immediately before returning, so it appears that the function is returning a new reference.