styleguide icon indicating copy to clipboard operation
styleguide copied to clipboard

Clarifying inheritance of class documentation in python.

Open OasisArtisan opened this issue 7 months ago • 2 comments

Wanted to clarify what the recommendation was for documenting child classes. What should be repeated and what should be referred back to the parent class.

For example, should we do this:

class Fruit:
  """

  Attributes:
    weight: The weight of the fruit in grams.
  """

class Apple(Fruit):
  """

  Attributes:
    weight: The weight of the fruit in grams.
    variety: The variety of the apple from the list ["granny smith", "honey_crisp"]
  """

Or this:

class Fruit:
  """

  Attributes:
    weight: The weight of the fruit in grams.
  """

class Apple:
  """

  Attributes:
    weight: See parent.
    variety: The variety of the apple from the list ["granny smith", "honey_crisp"]
  """

Keep in mind when arguments grow large it would be much harder to maintain the doc strings if they were copied for each child class. But its also more convenient for a user to have it copied.

Appreciate your thoughts.

OasisArtisan avatar May 07 '25 16:05 OasisArtisan

does your example have a typo ?

-class Apple:
+class Apple(Fruit):

vapier avatar May 07 '25 18:05 vapier

Yes it does. Assume Apple is a subclass of Fruit.

OasisArtisan avatar May 08 '25 12:05 OasisArtisan