sizmailov / pybind11-stubgen

Generate stubs for python modules
Other
218 stars 44 forks source link

Failing to fully resolve classes? #182

Closed ringohoffman closed 8 months ago

ringohoffman commented 8 months ago

When I run pybind11-stubgen on taichi,

$ pybind11-stubgen taichi._lib.core.taichi_python -o python

It seems to fail on expressions that do have corresponding pybind11-stubgen-generated class definitions. For example:

class ASTBuilder:
    def begin_frontend_struct_for_on_external_tensor(self, arg0: taichi::lang::ExprGroup, arg1: taichi::lang::Expr, arg2: DebugInfo) -> None:
        ...
    def begin_frontend_struct_for_on_snode(self, arg0: taichi::lang::ExprGroup, arg1: taichi::lang::SNode, arg2: DebugInfo) -> None:
        ...
class ExprGroup:
    def __init__(self) -> None:
        ...
    def push_back(self, arg0: Expr) -> None:
        ...
    def size(self) -> int:
        ...

Is this a problem in my configuration?

sizmailov commented 8 months ago

This should help: https://pybind11.readthedocs.io/en/latest/advanced/misc.html#avoiding-cpp-types-in-docstrings

ringohoffman commented 8 months ago

Thanks! Moving all the py::class_ declarations to the top was a super easy fix.

By the way... I did see something that might be unexpected. Kernel resolved correctly in a different method of this same class, but in the Callable, Kernel is left fully specified.

class Program:
    def compile_kernel(self, arg0: CompileConfig, arg1: DeviceCapabilityConfig, arg2: Kernel) -> CompiledKernelData:
        ...
    def create_kernel(self, arg0: typing.Callable[[taichi._lib.core.taichi_python.Kernel], None], arg1: str, arg2: AutodiffMode) -> Kernel:
        ...

What could be causing this, do you think?

sizmailov commented 8 months ago

Could you share the corresponding functions docstrings?

ringohoffman commented 8 months ago

I'm not sure what you mean by docstring.

Here is the declaration of create_kernel. It looks like a lambda function. Could that be the source of the issue?

Here is compile_kernel.

sizmailov commented 8 months ago

I mean the runtime __doc__ property, e.g. Program.compile_kernel.__doc__

ringohoffman commented 8 months ago
'compile_kernel(self: taichi._lib.core.taichi_python.Program, arg0: taichi._lib.core.taichi_python.CompileConfig, arg1: taichi._lib.core.taichi_python.DeviceCapabilityConfig, arg2: taichi._lib.core.taichi_python.Kernel) -> taichi._lib.core.taichi_python.CompiledKernelData\n'
'create_kernel(self: taichi._lib.core.taichi_python.Program, arg0: Callable[[taichi._lib.core.taichi_python.Kernel], None], arg1: str, arg2: taichi._lib.core.taichi_python.AutodiffMode) -> taichi._lib.core.taichi_python.Kernel\n'