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.
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 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']
```
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()

pip install -e .[dev]
parse_log_pytest
pytest
nose unittest2 pytest
3.6
requirements-tox.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
-e git+https://github.com/berkerpeksag/astor.git@b47718fa095e456c064d3d222f296fccfe36266b#egg=astor
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
certifi==2021.5.30
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1631916693255/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
linecache2==1.0.0
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
nose==1.3.7
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
six==1.17.0
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
traceback2==1.4.0
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
unittest2==1.1.0
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: astor
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib-metadata=4.8.1=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - argparse==1.4.0
      - linecache2==1.0.0
      - nose==1.3.7
      - six==1.17.0
      - traceback2==1.4.0
      - unittest2==1.1.0
prefix: /opt/conda/envs/astor

tests/test_code_gen.py::CodegenTestCase::test_fstring_trailing_newline
tests/test_code_gen.py::CodegenTestCase::test_annassign tests/test_code_gen.py::CodegenTestCase::test_arguments tests/test_code_gen.py::CodegenTestCase::test_async_comprehension tests/test_code_gen.py::CodegenTestCase::test_async_def_with_for tests/test_code_gen.py::CodegenTestCase::test_class_definition_with_starbases_and_kwargs tests/test_code_gen.py::CodegenTestCase::test_compile_types tests/test_code_gen.py::CodegenTestCase::test_comprehension tests/test_code_gen.py::CodegenTestCase::test_del_statement tests/test_code_gen.py::CodegenTestCase::test_dictionary_literals tests/test_code_gen.py::CodegenTestCase::test_double_await tests/test_code_gen.py::CodegenTestCase::test_elif tests/test_code_gen.py::CodegenTestCase::test_fstrings tests/test_code_gen.py::CodegenTestCase::test_imports tests/test_code_gen.py::CodegenTestCase::test_inf tests/test_code_gen.py::CodegenTestCase::test_matrix_multiplication tests/test_code_gen.py::CodegenTestCase::test_multiple_call_unpackings tests/test_code_gen.py::CodegenTestCase::test_non_string_leakage tests/test_code_gen.py::CodegenTestCase::test_output_formatting tests/test_code_gen.py::CodegenTestCase::test_pass_arguments_node tests/test_code_gen.py::CodegenTestCase::test_pow tests/test_code_gen.py::CodegenTestCase::test_right_hand_side_dictionary_unpacking tests/test_code_gen.py::CodegenTestCase::test_slicing tests/test_code_gen.py::CodegenTestCase::test_try_expect tests/test_code_gen.py::CodegenTestCase::test_tuple_corner_cases tests/test_code_gen.py::CodegenTestCase::test_unary tests/test_code_gen.py::CodegenTestCase::test_unicode_literals tests/test_code_gen.py::CodegenTestCase::test_with tests/test_code_gen.py::CodegenTestCase::test_yield
docs/changelog.rst .travis.yml tox.ini AUTHORS astor/code_gen.py
docs/changelog.rst .travis.yml tox.ini AUTHORS astor/code_gen.py