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

[BUG]: Linebreaks in docstring signature caused by default values #4734

Closed
3 tasks done
JeanElsner opened this issue Jul 8, 2023 · 0 comments
Closed
3 tasks done
Labels
triage New bug, unverified

Comments

@JeanElsner
Copy link
Contributor

JeanElsner commented Jul 8, 2023

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

5ccb9e4

Problem description

If the representation of default values includes linebreaks, the function signature added to the docstring will include those linebreaks. Multiple tools only parse the docstring line by line for a signature (Sphinx, pybind11-stubgen), so this will break otherwise functional compatibility.
For me this commonly happens with Eigen matrix arguments represented as Numpy arrays. If the default value representation of the Numpy array exceeds 70 characters or has more than one dimension, linebreaks will be printed. Simply stripping newlines before adding the signature to the function record fixed the issue for me, but I'm not sure this behavior is desired (cf. #2621 (comment)).

Reproducible example code

#include <pybind11/eigen.h>
#include <pybind11/pybind11.h>

#include "Eigen/Dense"

namespace py = pybind11;

PYBIND11_MODULE(_core, m) {
  m.def(
      "test", [](Eigen::Matrix3d mat) {},
      py::arg("mat") = Eigen::Matrix3d::Identity());
}

This will produce the docstring:

test(mat: numpy.ndarray[numpy.float64[3, 3]] = array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])) -> None

Is this a regression? Put the last known working version here if it is.

Not a regression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New bug, unverified
Projects
None yet
Development

No branches or pull requests

1 participant