sizmailov / pybind11-stubgen

Generate stubs for python modules
Other
238 stars 49 forks source link

Upgrade pybind11-stubgen crash stubs generation #120

Closed nyckmaia closed 1 year ago

nyckmaia commented 1 year ago

Hi, I have a C++/Pybind11 project in which I'am using pybind11-stubgen locally and also in Github actions to generate my Python stubs.

Topic 01: v0.16.2 + Old Syntax

I was using the pybind11-stubgen version v0.16.2 and everthing was working good!

In my Python script to generate the stubs, I was using this line below:

genStubsCommand = f"pybind11-stubgen maialib.maiacore --output-dir={stubsPath} --ignore-invalid=all --no-setup-py"

Question 1: Why I don't get the VS Code autocomple (stubs) inside the WSL (Linux) environment?

Topic 02: v1.1.0 + New Syntax

Well, after that, today I tried to use the lasted versio of pybind11-stubgen. The v1.1.0. To do so, I have to change the line above to remove deprecated arguments. The new line (new syntax) is below:

genStubsCommand = f"pybind11-stubgen maialib.maiacore --output-dir={stubsPath} --print-invalid-expressions-as-is --ignore-all-errors"

Question 2: Why I don't get the VS Code autocomple (stubs) in any operational system Python enviroment?

Topic 03: [ERROR 'json']

Using the v1.1.0, if I remove the --ignore-all-errors I got a single line output saying that pybind11-stubgen does not recognize the type 'json'. Yes, I'am using the nlohmann::json (link here) as input argument of many functions of my module. It was working good on v0.16.2.

Question 3: What is the problem with json?

Systems:

Could you help me?

Thank you,

sizmailov commented 1 year ago

I don't use Windows, VSCode, or WSL, so I can't answer the questions on those topics.

pybind11-stubgen does not recognize the type 'json'

Now pybind11-stubgen tries to resolve the names used in the output *.pyi files to add necessary import statements. Most likely your module uses a json object as argument/return value, but never defines what json is. If you run mypy on generated stubs it should provide a similar error.

It would be more helpful if you frame the questions in a smaller context with a minimal reproducible example.