Skip to content

Neither newlines nor triple quotes preserved… for docstrings #7

Description

@SamuelMarks
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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions