Python: Generate function stubs from C module

大城市里の小女人 提交于 2019-12-24 01:56:06

问题


I made a Python module in C/C++ with Python C API. I use setuptools.Extension in my setup.py.

It creates one .py file which loads a python module from some compiled .pyd file:

def __bootstrap__():
    global __bootstrap__, __loader__, __file__
    import sys, pkg_resources, imp
    __file__ = pkg_resources.resource_filename(__name__, 'zroya.cp36-win32.pyd')
    __loader__ = None; del __bootstrap__, __loader__
    imp.load_dynamic(__name__,__file__)
__bootstrap__()

But it does not generate python stubs for IDE autocomplete feature. I would like all exported functions and classes to be visible from .py file:

def myfunction_stub(*args, **kwargs):
    """
    ... function docstring
    """
    pass

Is it possible? Or do I have to create some python "preprocessor" which loads data from .pyd file and generate stubs with docstrings?

Source code is available on github.

来源:https://stackoverflow.com/questions/49409249/python-generate-function-stubs-from-c-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!