astunparse icon indicating copy to clipboard operation
astunparse copied to clipboard

Better support for docstrings

Open hauntsaninja opened this issue 5 years ago • 1 comments
trafficstars

Thanks for a useful library!

astunparse doesn't special case docstrings:

>>> print(astunparse.unparse(ast.parse('''def f(): """multi\n    line\n    docstring\n    """ ''')))

def f():
    'multi\n    line\n    docstring\n    '

whereas Python 3.9 handles it more idiomatically:

>>> print(ast.unparse(ast.parse('''def f(): """multi\n    line\n    docstring\n    """ ''')))

def f():
    """multi
    line
    docstring
    """

Note the implementation in Python 3.9 also handles other issues, like #38, better.

More generally, I was wondering if there's a plan to attempt to use the Python 3.9 implementation. Let me know if this is something you want and if you would want help!

hauntsaninja avatar Apr 14 '20 23:04 hauntsaninja

If you have ideas about backporting ast.unparse, please wait until the first beta. (As one of the authors of that functionality) I have still some prs to add some fixs about both docstrings and other things but I hope they will be merged until the first beta cut.

isidentical avatar Apr 15 '20 10:04 isidentical