The functionality seems obviously useful, but adding a magic publicOn Fri, Mar 15, 2013 at 6:47 PM, Warren Weckesser
> Hi all,
> In a recent scipy pull request (https://github.com/scipy/scipy/pull/459), I
> ran into the problem of ufuncs automatically generating a signature in the
> docstring using arguments such as 'x' or 'x1, x2'. scipy.special has a lot
> of ufuncs, and for most of them, there are much more descriptive or
> conventional argument names than 'x'. For now, we will include a nicer
> signature in the added docstring, and grudgingly put up with the one
> generated by the ufunc. In the long term, it would be nice to be able to
> disable the automatic generation of the signature. I submitted a pull
> request to numpy to allow that: https://github.com/numpy/numpy/pull/3149
> Comments on the pull request would be appreciated.
attribute to all ufuncs seems like a somewhat clumsy way to expose it?
Esp. since ufuncs are always created through the C API, including
docstring specification, but this can only be set at the Python level?
Maybe it's the best option but it seems worth taking a few minutes to
- If the first line of the docstring starts with "<funcname>(" and
ends with ")", then that's a signature and we skip adding one (I think
sphinx does something like this?) Kinda magic and implicit, but highly
- Declare that henceforth, the signature generation will be disabled
by default, and go through and add a special marker like
"__SIGNATURE__" to all the existing ufunc docstrings, which gets
replaced (if present) by the automagically generated signature.
- Give ufunc arguments actual names in general, that work for things
like kwargs, and then use those in the automagically generated
signature. This is the most work, but it would mean that people don't
have to remember to update their non-magic signatures whenever numpy
adds a new feature like out= or where=, and would make the docstrings
actually accurate, which right now they aren't:
In : np.add.__doc__.split("\n")
Out: 'add(x1, x2[, out])'
In : np.add(x1=1, x2=2)
ValueError: invalid number of arguments
- Allow some special syntax to describe the argument names in the
docstring: "__ARGNAMES__: a b\n" -> "add(a, b[, out])"
- Something else...
NumPy-Discussion mailing list