PyCQA / pydocstyle

docstring style checker
http://pydocstyle.org
MIT License
1.11k stars 188 forks source link

Add support for class attribute checking [google] #496

Open jtpavlock opened 4 years ago

jtpavlock commented 4 years ago

This is a feature request to add a check for class level attribute documentation.

As described in the google style guide:

If your class has public attributes, they should be documented here in an Attributes section and follow the same formatting as a function’s Args section.

class SampleClass:
    """Summary of class here.

    Longer class information....
    Longer class information....

    Attributes:
        likes_spam: A boolean indicating if we like SPAM or not.
        eggs: An integer count of the eggs we have laid.
    """

    def __init__(self, likes_spam=False):
        """Inits SampleClass with blah."""
        self.likes_spam = likes_spam
        self.eggs = 0

    def public_method(self):
        """Performs operation blah."""
sigmavirus24 commented 4 years ago

I don't actually maintain pydocstyle so take what I say with a grain of salt.

I think this might not be entirely tenable to do. Most attributes are created in __init__ but many __init__ methods aren't so simple as your example. This would require some amount of branch analysis, etc. Alternatively, instantiating the class would need to happen in order to find public attributes etc. Some attributes are publicly declared in other ways too, e.g.,

class AnotherClass:
    hates_spam = True
# Alternatively
import attr
@attr.s
class YetAnotherClass:
    hates_spam = attr.ib(default=True)

So this would have to be able to take all of those into account. It's not impossible, but it's also not trivial