Pylance-release: Missing docstrings for builtins

Created on 3 Jul 2020  路  17Comments  路  Source: microsoft/pylance-release

I am using the extension with Python 3.8.3. On hover for any function, the tooltip shows only the type information (of parameters, return value etc.).
I'd prefer it showing the documentation of the function (wherever available) as well, so that it is clear what the function is being used for. This can be seen demonstrated in the Pylance announcement blog post for the pandas library.

Environment data

  • Language Server version: 2020.6.1
  • OS and version: Windows 10 Version 20H2 (OS Build 19042.330)
  • Python version: 3.8.3 64-bit

Expected behaviour

Before installing pylance
image

Actual behaviour

After installing pylance
image

compiled enhancement fixed in next version

Most helpful comment

I'm happy to say that the next release (tomorrow?) will enable this:

str

print

It's going to be limited to the builtins for now, i.e. what you get in the global scope. There are other standard library modules that are compiled that could benefit from this, but that'll take a bit more effort to implement correctly and we'd like to continue to work on the compiled module story as a whole before expanding things.

All 17 comments

Additionally Replicated on:

  • OS and version: Windows 10 Version 2004 (OS Build 19041.329)
  • Python version: 3.7.4 64-bit

With the Microsoft Language Server I get this,
Microsoft
MicrosoftHover
which to me is the most helpful, as it contains a description of the function and optional parameters.

If I use Pylance I get this,
Pylance
PylanceHover
which to more experienced programmers might be more useful, but for me it is a bit messy and doesn't contain any overall description (docstring) of the function I'm hovering over.

Regardless of my choice of language server (except when I tried Jedi), enabling brackets in settings has no effect (bug):
BracketsEnabled

My expected behavior with Pylance (or Microsoft) Language Server and auto complete brackets enabled, is that the hover info is useful (makes use of the docstring and any type information) and automatically adds parenthesis with my curser placed inside it (|), when I use autocomplete.

My expected behavior with Pylance (or Microsoft) Language Server and auto complete brackets enabled, is that the hover info is useful (makes use of the docstring and any type information) and automatically adds parenthesis with my curser placed inside it (|), when I use autocomplete.

That's #37.

Hi,
Just wanted to say I am getting this issue too. I'd been using pyright/jedi previously, and the tooltips were showing docstrings. Switching over to pylance as the language server seems to replace docstrings with type signature only in some cases. Unfortunately, I rely on docstrings in the IDE/editor over memorizing my library APIs, so despite my desire to use pylance I have been forced to "downgrade" back to Jedi/pyright.

Here are some cases where pylance gives docstrings in pandas:
pd.DataFrame
pd.DataFrame.append
pd.DataFrame.to_numpy
pd.read_feather
Here are some cases where it just returns a type sig, no docstring:
pd.read_csv
pd.DataFrame.to_csv

This bug is specifically about the docstrings for builtins, which are distinct from the docstrings for other modules in that there is no file that can be read that contains the docstrings.

Our pandas type stubs mirror some of the docstrings to make sure we can access them (as pandas produces the docstrings at runtime from templates, defeating any static type checker that doesn't literally want to execute the code to try and pull info). If there are specific methods in pandas that we're missing or show inconsistently, I would suggest making a new issue, as the fix for that is going to be quite different than the fix for the builtins. read_csv being missing in particular is confusing, as that's definitely one we have mirrored.

Thanks Jake. I appreciate the response. And thanks to the whole team for the work they've put into the tooling. I apologise for mis-filing this issue.

Thanks Jake. I appreciate the response. And thanks to the whole team for the work they've put into the tooling. I apologise for mis-filing this issue.

sir, when will patch this issue?

Hopefully soon (this is the top voted issue, after all), but I don't have a timeframe at the moment, sorry.

This issue seems to be fairly specifically about builtins, although on my side the stubs without docstring (pylance shows this) vs source+docstring (pylance does not show this) issue does seem to be at play.

I have moved my comment to issue #170 which seems to be a better fit.

When will resolve the issue?

This is being worked on, and we will update this issue when it's finished and available.

I'm happy to say that the next release (tomorrow?) will enable this:

str

print

It's going to be limited to the builtins for now, i.e. what you get in the global scope. There are other standard library modules that are compiled that could benefit from this, but that'll take a bit more effort to implement correctly and we'd like to continue to work on the compiled module story as a whole before expanding things.

This issue has been fixed in version 2020.9.6, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202096-23-september-2020

@jakebailey:

I see that we have fixed this problem for builtins, what about custom function? Sorry if it might not fit this issue though, i dont want to create new issue for this.

If i use Microsoft Language Server:
image

If i use pylance:
image

If I hover on the function, it will display the docstring that I need. But it's very inconvenient to do so whenever i write something.

Is there any way to display the docstring like MLS? Thanks a lot :).

We definitely show info for your own functions. Based on the signature, that function appears to be using functools.wraps, which seems to drop the docstring. See #442 / #125 / microsoft/pyright#774.

This issue has been fixed in version 2020.9.6, which we've just released.

Just wondering: has this issue also been fixed in pyright?

No, the functionality to do this is implemented in Pylance (and doesn't affect type checking, only editor features). The builtins are compiled and that whole thing isn't quite settled; this is just a specific special case that we wanted to try out.

Was this page helpful?
0 / 5 - 0 ratings