2

I'm trying to document instance variables in my Python classes so they show up in VS Code when I hover over them. I've found that this works:

class TsCity:

def __init__(self) -> None:
    self.name: str = ""
    """The city name."""

But this is pretty ugly. I would ideally like to use the Google-style docstring instead:

self.name: str = ""  #: Doc comment *inline* with attribute

But this doesn't show up in VS Code properly. Is there a way to make this type of docstring work in VS Code?

starball
  • 20,030
  • 7
  • 43
  • 238
needarubberduck
  • 596
  • 3
  • 17
  • related: [What is the Python docstring format supported by Visual Studio Code?](https://stackoverflow.com/q/57017994/11107541) – starball Aug 12 '23 at 01:44
  • related: [In VSCode, how to get on-hover documentation shown for class properties documented in the class docstring?](https://stackoverflow.com/questions/76876719/in-vscode-how-to-get-on-hover-documentation-shown-for-class-properties-document?noredirect=1#comment135545324_76876719) – Camille Louédoc Aug 19 '23 at 16:39
  • ^only loosely related – starball Aug 19 '23 at 20:06

1 Answers1

2

This (#: lorem ipsum) is the Sphinx/Google style of attribute documentation (as opposed to the pep-0224 style (""" lorem ipsum """))

I asked the maintainers of the Python extension about whether there's an existing feature request issue ticket asking for Sphinx-style attribute documentation at https://github.com/microsoft/pylance-release/issues/1576#issuecomment-1668718385. One of them (Rich Chiodo) replied:

I don't believe so. But if it's not part of standard doc strings, it would probably take a lot of up votes for us to add it.

I take that to mean that- no, there is no way to get hover info for this style of attribute doc comments at the time of this writing- at least not with Microsoft's Python extension (the most popular Python extension at the time of this writing). Perhaps there's an extension that adds support for this, but I don't know of it. If you end up making a feature-request issue ticket to the Microsoft Python repo for this feature, please comment here linking to it, or suggest an edit to this post to add a link to it if you cannot comment.

starball
  • 20,030
  • 7
  • 43
  • 238