0

I am making a simple wrapper for a C/C++ library using Python C extensions and I am having problems with VS Code's intellisense. To simplify the problem, I pretty much have a the following files:

wrapper.cc with the actual code

// Function which calls the library or does whatever
static PyObject *foo_wrap(PyObject *self, PyObject *args)
{
    /* Do stuff here */
}


///// Definitions for the extension /////

static PyMethodDef Methods[] = {
    {"foo", foo_wrap, METH_VARARGS, "This is foo's docstring"},
    {NULL, NULL, 0, NULL}
};

static struct PyModuleDef module = {
    PyModuleDef_HEAD_INIT,
    "extension",
    "This is a wrapper for a library",
    -1,
    Methods
};

PyMODINIT_FUNC PyInit_extension(void) {
    return PyModule_Create(&module);
}

setup.py which is used to make the wrapper into a package by calling python setup.py install

from distutils.core import setup, Extension

def main():
    ext = Extension(
        "extension", 
        sources=["wrapper.cc"]
    )

    setup(name="extension",
          version="1.0.0",
          description="This is my extension",
          ext_modules=[ext])

if __name__ == "__main__":
    main()

I am then able to import it in my python code and use the prepared method

import extension
extension.foo(...)

and I can even see the appropriate docstrings using extension.__doc__ or extension.foo.__doc__. However, I can't seem to persuade VS Code's intellisense to display these docstrings, autocomplete, or at least acknowledge, that the extension has some functions available. It is not throwing me any errors, it just doesn't do pretty much anything. For example hovering over the foo function only displays (function) add_to_tree: Any instead of its docstring, which I would like to see.

I tried adding the a path to the .so file, which was created by the setup.py into setting.json python.analysis.extraPaths but that still did not help.

The only relevant thing I managed to google was this, however, there pretty much wasn't any solution to my problem. The only answer there by Brett Cannon mentions, that there might be problems when compiling in place, but I don't think that is my case (or maybe I don't fully understand how "in place" works).

V.Iron
  • 1
  • Sorry my machine can't reproduce your issue, if you have a full bug report and steps to reproduce, you can report it on [GitHub](https://github.com/microsoft/vscode-python/issues/new/choose) for a response. – JialeDu Jul 06 '23 at 07:23

1 Answers1

0

Try to switch the python language server, by default vscode uses Pylance, add the following setting to switch Jedi the language server

    "python.languageServer": "Jedi",
JialeDu
  • 6,021
  • 2
  • 5
  • 24