How to generate .pyi files for a compiled Python extension?
Asked Answered
L

1

6

I build a compiled Python extension (.pyd file) with C++ and pybind11. I would like to generate a single Python interface .pyi file for my .pyd file.

There are a few similar questions referring to the mypy stubgen module, however, this one produces a UnicodeError trying to run stubgen Dummy where Dummy is Dummy.pyd file:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 2: invalid start byte

Another project, make-stub-files does not work with .pyd files at all, giving the ('not a python file' error.

Are there any tools that could let me generate .pyi files either from the source .cpp files or from compiled .pyd files?

The issue is registered in the mypy GitHub repository.

Linn answered 27/6, 2018 at 7:55 Comment(1)
See also (no answer): #49409749Denizen
L
1

The issue was registered in the mypy GitHub source repository and fixed in a pull request.

The reason for the issue was that when mypy was trying to figure out whether a given module is a Python extension it checked for the .so file extension used on Linux, but did not check for the .pyd file extension used on Windows.

Linn answered 9/7, 2018 at 6:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.