-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Render NaN default argument as numpy.nan #2243
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
Conversation
Example: generated signature changes from foo(x: float = nan) to foo(x: float = numpy.nan)
std::isnan is not available on gcc-4.8
9136bac
to
a30af8f
Compare
|
54fd417
to
d4784d1
Compare
On second thought I think I chose wrong place inject the change. The underlying bigger problem is pybind11/include/pybind11/pybind11.h Lines 210 to 213 in eeb1044
For example new extension point can be introduced with something like tempate<typename T>
struct value_formatter {
value_formatter(const T& value);
const char* operator() const;
}
// and later in pybind11.h
if (a.descr)
a.descr = strdup(a.descr);
else if (a.value)
a.descr = strdup(value_formatter(cast(a.value))()); |
I'm curious: what's wrong with just |
The problem is that generated signatures are not valid in sense of interpretation as stubs signatures. The situation is worse when default value is not even valid python expression, e.g. Documentation matters therefore I think it's worth to produce toolable docstrings. |
This PR changes how nan values are rendered in docstring.
Implemented via float overloads for
py::arg_v
. Might be considered as an overkill for such a small change. On the other handnan
values are quite common sentinel values so it might be worth it to generate more toolable docstrings.compare.cpp