4

When I right click on a function and then select "Go to definition" there shows up a module with that function, but it only shows the parameters which have to be passed to it, and I can't see anything about the body of the function.

Here is what's shown when I went to the definition of itertools.dropwhile:

go-to-definition

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Chul-ian
  • 90
  • 1
  • 8
  • 3
    There is no function body to be shown. This is a module that's implemented in C, not Python. – jasonharper Dec 14 '19 at 22:37
  • Oh. And the same happens with ```math.sqrt```? Because when I go to definition it shows ```def sqrt(x: SupportsFloat) -> float: ...```. And also with ```print``` function. – Chul-ian Dec 14 '19 at 22:47
  • What @jasonharper said will apply to many (but not all) of the built-ins…which means you'll actually have to read its [documentation](https://docs.python.org/3/). – martineau Dec 15 '19 at 00:32
  • The actual implementation is in C, here: [cpython/itermodules.c](https://github.com/python/cpython/blob/3.8/Modules/itertoolsmodule.c#L1153). – Gino Mempin Dec 15 '19 at 01:07

2 Answers2

6

As mentioned in the comments, VSCode can only show you source code it has access to, and many of the Python builtins and stdlib (including the itertools module) are implemented in compiled C -- there's no source code to show you.

Adam Smith
  • 52,157
  • 12
  • 73
  • 112
0

Sometimes this happens if you develop code that runs inside an environment whose libraries are not visible in your main OS.

One way to solve this is by opening the terminal in VSCode and doing a pip install <library> to install the library and make VSCode aware of it.

Otrebus
  • 1
  • 1
  • 2
  • This is a good point (although note that this is the `itertools` library from the standard lib, so no need to install it; also, `pip install ` is not always the correct way forward and depends on the development environment). However, in this case, there is no Python code to show for the definition of this function. VSCode then falls back on showing the [type stub](https://mypy.readthedocs.io/en/stable/stubs.html) (if any) for that function/value, so it's doing the right thing here. – KevinOrr Nov 20 '22 at 14:49