Skip to content

Document in overloaded function is placed in wrong place #85

@KowerKoint

Description

@KowerKoint

When a function is overloaded, documentation comments is placed in wrong place.

For example, the C++ wrapper is below:

#include <iostream>
#include <pybind11/pybind11.h>
int add_int(int x, int y) {
    return x + y;
}
double add_double(double x, double y) {
    return x + y;
}

namespace py = pybind11;

PYBIND11_MODULE(python_example, m) {
    m.doc() = "pybind11 example plugin";
    m.def("add", &add_int, "Add x and y(int)", py::arg("x"), py::arg("y"));
    m.def("add", &add_double, "Add x and y(double)", py::arg("x"), py::arg("y"));
}

then, __init__.pyi below is generated:

"""pybind11 example plugin"""
from __future__ import annotations
import python_example
import typing

__all__ = [
    "add"
]


@typing.overload
def add(x: float, y: float) -> float:
    """
    Add x and y(int)

    Add x and y(double)
    """
@typing.overload
def add(x: int, y: int) -> int:
    pass

I expect it to be like below:

"""pybind11 example plugin"""
from __future__ import annotations
import python_example
import typing

__all__ = [
    "add"
]


@typing.overload
def add(x: float, y: float) -> float:
    """
    Add x and y(double)
    """
@typing.overload
def add(x: int, y: int) -> int:
    """
    Add x and y(int)
    """

help(add) prints separated documents, so I think this is pybind11-stubgen problem.

Is there a solution to fix it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions