3

I try to find the docstring of the numpy.random.random() function in vscode. To do this i can keep navigating to the definition using go to definition from the menu or by pressing the f12 key.

...but i end up navigating to this line of code:

    def random(self, size: None = ...) -> float: ...  # type: ignore[misc]

Not only do i not find the docstring, but i dont understand what the elipses (three dots ...) do or what this line of code means. There are various explanations of elipses for use in arrays in numpy, but not for functions or how i can navigate to the docstring from this.

So, where is the docstring of the function ? (ie. the same docstring that i would see by hovering over the function)

D.L
  • 4,339
  • 5
  • 22
  • 45
  • 1
    The docstring for `numpy.random.random` is found in `numpy.random.random.__doc__`. I don't think that's what you actually wanted to know; I suspect your question is, "how can I get vscode to show me `numpy.random.random`'s signature?", or maybe, "how can I interpret the signature for `numpy.random.random` which vscode shows me?". Note that `numpy.random.random` is a compiled function written in Cython, and it's signature is not available for reflection. That's what `...` means in this context. – rici Sep 25 '22 at 16:23
  • You can find the official documentation at https://numpy.org/doc/stable/reference/random/generated/numpy.random.random.html. In this case, that's just an HTML formatted version of `numpy.random.random.__doc__`, which is roughly what `help(numpy.random.random)` would show you in the Python REPL. – rici Sep 25 '22 at 16:24
  • @rici, excellent comment. It is useful to know, that it `python` / `numpy` works this way. So i will summarise by saying that if a user wants to find the docs for `Cython` based functions, then they have to search the web / docs and **not** navigate python modules... – D.L Sep 25 '22 at 16:57
  • I don't know what you mean by "navigate python modules". As I said, the docstring is available in the function object itself, `numpy.random.random.__doc__`. Is that not a form of navigation? However, a given IDE (vscode, in this case) might not show you that string, which is a different issue. So the docstring is there. What you cannot get from `random` is its signature, because not all compiled functions make their signature available for reflection. – rici Sep 25 '22 at 17:01
  • Cython is just an instance of the problem. `math.log` (which is written in C), also hides its signature, although most `math` module functions work fine. See `inspect.signature. for the actual reflection methods, if you're interested. – rici Sep 25 '22 at 17:04

0 Answers0