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

Docstrings display broken for dataclasses #640

Closed
ARF1 opened this issue Nov 22, 2020 · 8 comments
Closed

Docstrings display broken for dataclasses #640

ARF1 opened this issue Nov 22, 2020 · 8 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@ARF1
Copy link

ARF1 commented Nov 22, 2020

Environment data

  • Language Server version: 2020.11.371526539
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): Miniconda Python 3.9

Actual behaviour

Docstrings of dataclasses are not show for class instantiation:

image

You should attach the class docstring to your internally synthesized __init__ function.

Expected behaviour

Display docstrings for dataclass instantiation like you already do for normal classes:
image

@erictraut
Copy link
Contributor

Thanks for the suggestion.

Pylance doesn't display class docstrings for constructors in any class, so this issue isn't specific to dataclasses. I guess it's more of an issue with dataclasses because the constructor is implicit.

Maybe Pylance should always display the class docstring if the constructor (__init__ or __new__ method) has no docstring. Needs more thought & discussion.

@erictraut erictraut added enhancement New feature or request needs decision Do we want this enhancement? and removed triage labels Nov 22, 2020
@ARF1
Copy link
Author

ARF1 commented Nov 22, 2020

Maybe Pylance should always display the class docstring if the constructor (__init__ or __new__ method) has no docstring. Needs more thought & discussion.

FWIW This suggestion gets a definite yes from me. If a programmer has made the effort of actually writing a docstring, it should be displayed if it is even remotely relevant.

I cannot imagine a single instance where a programmer did not write a docstring for their constructor because they explicitly did not want a docstring to be displayed for the constructor. It simply means that they are lazy and felt that they explained everything in the class docstring.

And if a unicorn programmer should exist that explicitly does not want any docstring being shown for their constructor, they can always write an empty docstring for their constructor.

@savannahostrowski
Copy link
Contributor

We've changed the behaviour so that we display the docstring as you described above.

image

@ARF1
Copy link
Author

ARF1 commented Jun 8, 2021

@savannahostrowski That's great. Many thanks!

@Antyos
Copy link

Antyos commented Jun 14, 2021

@savannahostrowski Was this change included in Pylance v2021.6.1 or has it not been released yet?

I can repeat the example you showed above, but I cannot get the class docstring to appear if the __init__() docstring is not present.
image

Additionally, no docstrings will show up in the constructor if the class is decorated as @dataclass:
image

@jakebailey
Copy link
Member

You're right, it doesn't work.

image

I mistakenly tested with the "expected behavior" snippet in the original issue, which was of course a simulation of what was expected.

@jakebailey jakebailey reopened this Jun 14, 2021
@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed enhancement New feature or request needs decision Do we want this enhancement? labels Jun 16, 2021
@erictraut
Copy link
Contributor

This will be fixed in the next release.

@bschnurr
Copy link
Member

This issue has been fixed in version 2021.6.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202162-16-june-2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 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

6 participants