Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm: How to get class attributes to be listed in Quick Documentation pop-up?

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.

like image 505
Egor Panfilov Avatar asked Oct 16 '18 21:10

Egor Panfilov


2 Answers

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

like image 198
Benbb96 Avatar answered Oct 23 '22 12:10

Benbb96


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!

like image 3
Jakub Duchon Avatar answered Oct 23 '22 10:10

Jakub Duchon