docformatter icon indicating copy to clipboard operation
docformatter copied to clipboard

Class attributes docstrings aren't formatted

Open dgellow opened this issue 3 years ago • 2 comments

Hi there,

I noticed that when declaring a class attribute with a docstring docformatter doesn't seem to take in account and reformat it.

An example:

class MyClass:
  my_attribute: str
  """This is a very, very, very long docstring that should really be reformatted nicely by docformatter. But it is currently ignored and will stay on a very, very, very long line!"""

While I don't believe that class attribute docstrings are explicitly mentioned in an active PEP they are very common, and are for example supported by Sphinx, Numpydoc, mkdocstrings, and Pylance.

dgellow avatar Mar 31 '22 11:03 dgellow

Per PEP-257, "The docstring for a class should summarize its behavior and list the public methods and instance variables." This can be found in the multi-line docstring section. Thus, PEP-257 treats class docstrings as multi-line docstrings and docformatter should format them as such.

weibullguy avatar Jul 24 '22 16:07 weibullguy

I misread this issue. It is concerned with class attribute docstrings, not class docstrings. Class attribute docstrings are discussed in PEP 258, which is included in PEP 257 by reference. Since this request is for functionality not explicitly required by PEP 257, it is considered an enhancement, not a bug.

weibullguy avatar Aug 03 '22 01:08 weibullguy