• Felix Yan's avatar
    Fix string parsing with newline (#123) · c72349f3
    Felix Yan yazdı
    When looping over a joined str, if a node is ast.Str and the value is
    just a newline "\n", the write() function adds an additional indentation
    after it, which fails to represent the original string. By calling
    self.result.append() here directly the issue is resolved.
    
    The added test could show the issue. With code_gen unmodifed, it fails
    with the following error:
    
    ```
    AssertionError: "if 1:\n    x = f'{host}\\n\\t{port}\\n    '" != "if
    1:\n    x = f'{host}\\n\\t{port}\\n'"
      if 1:
          -     x = f'{host}\n\t{port}\n    '?
          ----
          +     x = f'{host}\n\t{port}\n'
    ```
    
    Which is exactly the problem.
    
    This fixes parsing issues with many of Python 3.7's stdlib. Namely the
    following ones:
    
    /usr/lib/python3.7/warnings.py
    /usr/lib/python3.7/netrc.py
    /usr/lib/python3.7/test/test_embed.py
    /usr/lib/python3.7/test/support/testresult.py
    /usr/lib/python3.7/idlelib/grep.py
    
    Fixes #119
    c72349f3
To find the state of this project's repository at the time of any of these versions, check out the tags.
changelog.rst 6.32 KB