It seems to me that pydoc only works on py source code files.
Can it be used on a compiled pyd file in some way? The error I get in attempting that is
ValueError: source code string cannot contain null bytes
which arises, obviously, due to the fact that the compiled pyd contains NUL bytes.
Looking at the
pydoclibrary, specially its source code (3.9), the functionimportfileworks with .py and .pyc, but does not with .pyo nor .pyd files.It may be possible to write custom code to parse the content of a .pyd file and re-use parts of
pydocto generate the documentation, but I think it is not simple.Another way is through the builtin
helpthat callspydoc. here is a proof of concept :(I have installed Cython in my venv, so that I can compile .py files into .pyd)
I run
python setup.py build_ext --inplacewhich produces themain.cp36-win_amd64.pydfile.I move this file into another directory (to not mess the import later), and I use this file :
which is in the same directory than the .pyd file (and nothing else). When ran, it prints :
which proves it is possible.
Looking at the CPython implementation for
helpas of 3.9 we can see it only doesreturn pydoc.help(*args, **kwds). So we can callpydocdirectly :and still have the same output.
But it prints its output directly on stdout, which is not convenient. Looking at its Cpython 3.9 implementation that it uses by default its
outputfield, which is a property (see here) that returnssys.stdoutif nooutputhas been provided to the constructor, which is the case for the defaultHelper.So by constructing a new
Helperobject whose output is an in-memoryio.StringIO, we have the following code :I think it answers your question : you can write a script that will get the pydoc from a .pyd file. It is just not as straightforward, because it is very less common.