Closed
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
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