typed-astunparse icon indicating copy to clipboard operation
typed-astunparse copied to clipboard

Neither newlines nor triple quotes preserved… for docstrings

Open SamuelMarks opened this issue 5 years ago • 0 comments

import typed_ast.ast3
import typed_astunparse

code = '''
class Snake(object):
    """
    Om nom nom
    
    and some more nom nom nom
    """
    
    def bite(me: str) -> bool:
        return me == 'cython'
'''
roundtrip = typed_astunparse.unparse(typed_ast.ast3.parse(code))
print(roundtrip)

Outputs:

class Snake(object):
    '\n    Om nom nom\n    \n    and some more nom nom nom\n    '

    def bite(me: str) -> bool:
        return (me == 'cython')

Use-case: I'm writing a docstring transformer

SamuelMarks avatar Jul 13 '20 09:07 SamuelMarks