astunparse
astunparse copied to clipboard
Better support for docstrings
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!
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.