pep8ify icon indicating copy to clipboard operation
pep8ify copied to clipboard

Docstrings should be indented at more than just the first line

Open dhermes opened this issue 11 years ago • 3 comments

See https://gist.github.com/dhermes/85c3a3a464d2cff312ea for a (super hacky) way to make this work.

Currently, pep8ify takes

def hello_func(name):
  """Prints hello with the name.

  Args:
    name: String, to print.
  """
  print 'Hello %s, nice to meet you.' % (name,)

and turns it into

def hello_func(name):
    """Prints hello with the name.

  Args:
    name: String, to print.
  """
    print 'Hello %s, nice to meet you.' % (name, )

Running indent_docstrings.py on it gives the desired:

def hello_func(name):
    """Prints hello with the name.

    Args:
      name: String, to print.
    """
    print 'Hello %s, nice to meet you.' % (name, )

dhermes avatar Sep 27 '14 06:09 dhermes

Agreed.

Unfortunately, I don't have much time to spend on this project. If someone has time to make a pull request, I will happily merge.

spulec avatar Oct 13 '14 02:10 spulec

I'm happy to take a stab. Care to point out the entry point in the code where indenting occurs? Also, do you use ast to parse the tree or something else?

dhermes avatar Oct 13 '14 03:10 dhermes

We use lib2to3, which is a bit of a wrapper around the ast.

I think this is probably occurring as part of fix_indentation, but I'm not positive.

spulec avatar Oct 21 '14 22:10 spulec