Repository: berkerpeksag/astor

Issue:
Test failure in Python 3.6.3
Looks like a test-only failure, though.

```
======================================================================
FAIL: test_convert_stdlib (tests.test_rtrip.RtripTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/python-astor/src/astor-0.6/tests/test_rtrip.py", line 24, in test_convert_stdlib
    self.assertEqual(result, [])
AssertionError: Lists differ: ['/usr/lib/python3.6/test/test_fstring.py'[34 chars].py'] != []

First list contains 2 additional elements.
First extra element 0:
'/usr/lib/python3.6/test/test_fstring.py'

+ []
- ['/usr/lib/python3.6/test/test_fstring.py',
-  '/usr/lib/python3.6/idlelib/grep.py']
```

Discussion:
radomirbosak: The only failing environment is `pypy3.3-5.2-alpha1` which fails for `master` branch too, and is fixed in https://github.com/berkerpeksag/astor/pull/102
berkerpeksag: > The only failing environment is pypy3.3-5.2-alpha1 which fails for master branch too, and is fixed in #102

This one is almost ready to be merged. We can move that change into this one and rebase #102 after we merge this.

Also, could you add a note in `docs/changelog.rst`? This is a bugfix so you'll need to add a new "Bug fixes" subsection.
berkerpeksag: Oh, and please add your name to https://github.com/berkerpeksag/astor/blob/master/AUTHORS
radomirbosak: Authors and changelog updated; the tox/travis environment-change commit from #102 was moved here.

Patch:
diff --git a/.travis.yml b/.travis.yml
index df42c87..f789743 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,7 +8,7 @@ python:
   - 3.5
   - 3.6
   - pypy
-  - pypy3.3-5.2-alpha1
+  - pypy3.5
   - 3.7-dev
 matrix:
   allow_failures:
diff --git a/AUTHORS b/AUTHORS
index 39d96d5..9949ccc 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -12,3 +12,4 @@ And with some modifications based on Armin's code:
 * Zack M. Davis <code@zackmdavis.net>
 * Ryan Gonzalez <rymg19@gmail.com>
 * Lenny Truong <leonardtruong@protonmail.com>
+* Radomír Bosák <radomir.bosak@gmail.com>
diff --git a/astor/code_gen.py b/astor/code_gen.py
index 47d6acc..c5c1ad6 100644
--- a/astor/code_gen.py
+++ b/astor/code_gen.py
@@ -580,6 +580,9 @@ class SourceGenerator(ExplicitNodeVisitor):
 
             index = len(result)
             recurse(node)
+
+            # Flush trailing newlines (so that they are part of mystr)
+            self.write('')
             mystr = ''.join(result[index:])
             del result[index:]
             self.colinfo = res_index, str_index  # Put it back like we found it
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 781f39d..0faff36 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -22,6 +22,16 @@ New features
 
 .. _`Issue 86`: https://github.com/berkerpeksag/astor/issues/86
 
+Bug fixes
+~~~~~~~~~
+
+* Fixed a bug where newlines would be inserted to a wrong place during
+  printing f-strings with trailing newlines.
+  (Reported by Felix Yan and contributed by Radomír Bosák in
+  `Issue 89`_.)
+
+.. _`Issue 89`: https://github.com/berkerpeksag/astor/issues/89
+
 
 0.6.2 - 2017-11-11
 ------------------
diff --git a/tox.ini b/tox.ini
index 5149f5c..e364485 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = py26, py27, py33, py34, py35, py36, pypy, pypy3.3-5.2-alpha1
+envlist = py26, py27, py33, py34, py35, py36, pypy, pypy3.5
 skipsdist = True
 
 [testenv]


Test patch:
diff --git a/tests/test_code_gen.py b/tests/test_code_gen.py
index 0638d9a..1a80445 100644
--- a/tests/test_code_gen.py
+++ b/tests/test_code_gen.py
@@ -476,6 +476,12 @@ class CodegenTestCase(unittest.TestCase, Comparisons):
         '''
         self.assertAstRoundtrips(source)
 
+    def test_fstring_trailing_newline(self):
+        source = '''
+        x = f"""{host}\n\t{port}\n"""
+        '''
+        self.assertSrcRoundtripsGtVer(source, (3, 6))
+
 
 if __name__ == '__main__':
     unittest.main()