There seem to be two places where you can put docstrings for a class:
class MyClass(object):
""" Summary of MyClass
Body
...
"""
__init__
constructor:...
def __init__(self, arg1, arg2):
""" Summary of MyClass
Body
...
"""
Which is preferred? Or is it okay to have both?
They can both exist, since they are both intended for different things.
The docstring for a class should summarize its behavior and list the public methods and instance variables. If the class is intended to be subclassed, and has an additional interface for subclasses, this interface should be listed separately (in the docstring). The class constructor should be documented in the docstring for its
__init__
method. Individual methods should be documented by their own docstring.
Emphasis mine. This reference is from PEP 257 -- Docstring Conventions
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