11

I use Google Style Python Docstrings like in this Example for my Django's project. When i create a class and using an attributes notation in docstring, Pycharm always say - "Unresolved reference".

class Post(models.Model):
    """
    Class for posts.

    Attributes:
        title(str): Post title.
    """
    title = models.CharField(max_length=120)

I understand that PyCharm doesn't see self for title and def __init__() function and write this error, but in Django I've never seen using def __init__() for classes inherited from models.

What should I do? Is this my error or does PyCharm not see context in this case? Should I use def __init__() or something else or write docsting in another way?

Joey
  • 1,436
  • 2
  • 19
  • 33
Denis Savenko
  • 829
  • 1
  • 13
  • 29
  • 2
    You can ignore that kind of errors with Django or create an issue in youtrack to support this feature. I guess it's not implemented in pycharm professional. – Sergei Zherevchuk Jul 02 '16 at 19:14

3 Answers3

7

PyCharm does not appear to have support for this currently. The active issue for this in JetBrains issue tracker is https://youtrack.jetbrains.com/issue/PY-16760, please consider upvoting it to get it fixed. The only workaround if you want to avoid seeing these "Unresolved reference" errors in your docstrings is to disable the inspection in Preferences > Editor > Inspections > Unresolved references.

Another option that I have tried in the past is removing the "Attributes:" header and writing my attribute documentation on the same indentation level as the rest of the docstring. This no longer gives you a warning, but you are no longer conforming 100% to the Google Docstring Style Guide.

00willo
  • 68
  • 4
5

I solved this issue by adding a '# noqa' after the 'Attributes:', because i did not want to disable the unresolved reference warning.

So this would be the final docstring:

"""
Class for posts.

Attributes:  # noqa
    title(str): Post title.
"""
0

The following works for me: In your docstrings, writing Attribute: instead of Attributes: makes the error disappear. That allows you to keep the indentation level

KingOtto
  • 840
  • 5
  • 18