Skip to content
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

Missing docstrings for builtins #49

Closed
LordKa0S opened this issue Jul 3, 2020 · 17 comments
Closed

Missing docstrings for builtins #49

LordKa0S opened this issue Jul 3, 2020 · 17 comments
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@LordKa0S
Copy link

LordKa0S commented Jul 3, 2020

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

@LordKa0S
Copy link
Author

LordKa0S commented Jul 3, 2020

Additionally Replicated on:

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

@huguesv huguesv added the bug Something isn't working label Jul 7, 2020
@jakebailey jakebailey added enhancement New feature or request needs spec and removed bug Something isn't working labels Jul 13, 2020
@jakebailey jakebailey changed the title Docstrings are not displayed with pylance Missing docstrings for builtins Jul 13, 2020
@Brodersen
Copy link

Brodersen commented Aug 5, 2020

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.

@jakebailey
Copy link
Member

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.

@JonathanTay
Copy link

JonathanTay commented Aug 17, 2020

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

@jakebailey
Copy link
Member

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.

@JonathanTay
Copy link

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.

@chenyidao110
Copy link

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?

@jakebailey
Copy link
Member

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

@jakebailey jakebailey added needs investigation Could be an issue - needs investigation compiled and removed needs spec labels Sep 2, 2020
@cpbotha
Copy link

cpbotha commented Sep 3, 2020

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.

@chenyidao110
Copy link

When will resolve the issue?

@jakebailey
Copy link
Member

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

@jakebailey
Copy link
Member

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.

@jakebailey jakebailey added fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed needs investigation Could be an issue - needs investigation labels Sep 22, 2020
@jakebailey
Copy link
Member

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

@jackblk
Copy link

jackblk commented Oct 9, 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 :).

@jakebailey
Copy link
Member

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.

@YodaEmbedding
Copy link

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?

@jakebailey
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

9 participants