Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document in overloaded function is placed in wrong place #85

Closed
KowerKoint opened this issue Aug 24, 2022 · 2 comments
Closed

Document in overloaded function is placed in wrong place #85

KowerKoint opened this issue Aug 24, 2022 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@KowerKoint
Copy link

KowerKoint commented Aug 24, 2022

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?

@sizmailov sizmailov added enhancement New feature or request help wanted Extra attention is needed labels Sep 30, 2022
@sizmailov
Copy link
Owner

Hi!

Thanks for the report. This is not implemented, but it's doable. The only trick is to ensure that all custom (i.e. non-pybind) docstrings behave well too.

Note the upcoming function signature change in docstrings: pybind/pybind11#2621

sherlockdoyle added a commit to sherlockdoyle/pybind11-stubgen that referenced this issue May 4, 2023
@sizmailov
Copy link
Owner

Closed with #112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants