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.
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 :
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With