14

I found this really annoying that Quick Documentation doesn't show attributes, listed in class' docsting. I thought that the reason was incorrect or unsupported docstring format, but behavior is the same for both reST and Google styles (I set them properly in Python Integrated Tools).


My current docstring style is Google. Let me show what's wrong in pictures:

Here's Actor class. As you see, Attributes section presents in docstring but not in Quick Documentation pop-up.

Also, there is no annotation on attribute world_id.

Args of __init__ recognition works like a charm.

Let's add docstring directly to attribute (how it was suggested in answer). Works great, isn't it?

And call Quick Documentation for attribute inside another method. Wow, there's no description again.


How to get things working? How to set up PyCharm so it catch up class' attributes and show 'em in Quick Documentation?

PyCharm 2018.2.4 (Community Edition). Ubuntu 16.04.

Egor Panfilov
  • 159
  • 1
  • 8
  • In the PyCharm documentation, it says that "PyCharm recognizes inline documentation created in accordance with [PEP-257](https://www.python.org/dev/peps/pep-0257/)". – lmiguelvargasf Oct 16 '18 at 22:07
  • @lmiguelvargasf, there's line in PEP-257: "The docstring for a class should summarize its behavior and list the public methods and instance variables". I suppose that's enough for PyCharm to recognize attributes. – Egor Panfilov Oct 16 '18 at 22:54

2 Answers2

7

Here's how I managed to display class attributes in the Docstring in Pycharm 2020.3.3 (I use professional edition) :

class TestModel(models.Model):
    """
    A Test model to see the class attributes in the docstring

    Attributes:

    - :class:`str` name --> The name of the test object
    - :class:`datetime` created_at --> Date and time when the instance was created
    """
    name = models.CharField(max_length=50)
    created_at = models.DateTimeField(auto_now_add=True)

Note that without the Attributes: line, it won't work as expected.

And this is how it is shown in the quick documentation :

enter image description here

Benbb96
  • 1,973
  • 1
  • 12
  • 21
4

For anyone who is still struggling with this and stumbles upon this post (as I did).

PyCharm doesn't support this currently - or should I rather say that it still doesn't support it. Not for Google style docstring, neither for structuredText. There are multiple tickets regarding this issue on their Youtrack support website.

E.g. https://youtrack.jetbrains.com/issue/PY-17945 - this issue sits there for over 5 years!

Jakub Duchon
  • 101
  • 3
  • 8