yapf icon indicating copy to clipboard operation
yapf copied to clipboard

Reformatting docstrings and comments

Open tschijnmo opened this issue 9 years ago • 7 comments

By running the current 0.10.0 version of yapf on

def func(a):
    """Do something awesome.

    This is a long long long description of the awesome work that is done by this function.  Despite being very detailed, it runs over the column limit.
    """

we basically cannot get any formatting of the docstring. Could you please help me if it is a feature that is currently absent from yapf? If it could be reformatted into something like,

def func(a):
    """Do something awesome.

    This is a long long long description of the awesome work that is done by
    this function.  Despite being very detailed, it runs over the column limit.
    """

quite a lot of something like gq in vim could be saved. If it could reformat the docstring in the default Sphinx, numpy, or Google format, probably it could be even more helpful.

tschijnmo avatar Jun 20 '16 19:06 tschijnmo

I would also appreciate the option to have a different maximum line length for comments.

JorisE avatar Jul 11 '16 18:07 JorisE

@tschijnmo: I just ran into https://github.com/myint/docformatter. That might help?

JorisE avatar Jul 11 '16 19:07 JorisE

Yes please. YAPF doesn't seem to reformat docstrings at all. Intended behavior?

carlthome avatar Aug 01 '16 15:08 carlthome

I've done this internally, and it's a mess. There are so many conditions that are needed. The best way would be to create a lib2to3 fixer. If someone wanted to offer a patch, I would consider it.

bwendling avatar Oct 03 '16 06:10 bwendling

I assume this goes for reflowing comments as well? Would be handy for sure.

coxley avatar Oct 21 '16 05:10 coxley

How about just piggybacking off of https://github.com/myint/docformatter? It just doesn't seem inline with YAPF's philosophy of being like go fmt in that a canonical formatting should be produced, when it totally ignores docstrings at the moment.

carlthome avatar Oct 21 '16 13:10 carlthome

How about doctest?

def f():
    """
    >>> 1+2  # -> 1 + 2
    3
    """

e-kwsm avatar Feb 26 '24 01:02 e-kwsm