@@ -200,7 +200,7 @@ def future_import(feature, node):
200200 shebang_encoding_idx = None
201201
202202 for idx , node in enumerate (root .children ):
203- # If it's a shebang or encoding line, attach the prefix to
203+ # Is it a shebang or encoding line?
204204 if is_shebang_comment (node ) or is_encoding_comment (node ):
205205 shebang_encoding_idx = idx
206206 if node .type == syms .simple_stmt and \
@@ -218,11 +218,13 @@ def future_import(feature, node):
218218 import_ = FromImport (u'__future__' , [Leaf (token .NAME , feature , prefix = " " )])
219219 if shebang_encoding_idx == 0 and idx == 0 :
220220 # If this __future__ import would go on the first line,
221- # detach the shebang / encoding prefix from the current first line
221+ # detach the shebang / encoding prefix from the current first line.
222222 # and attach it to our new __future__ import node.
223- import_ .prefix = root .children [0 ].prefix
224- root .children [0 ].prefix = u''
225- children = [import_ , Newline ()]
223+ import_ .set_prefix (root .children [0 ].get_prefix ())
224+ root .children [0 ].set_prefix (u'' )
225+ # End the __future__ import line with a newline and add a blank line
226+ # afterwards:
227+ children = [import_ , Newline ()]
226228 root .insert_child (idx , Node (syms .simple_stmt , children ))
227229
228230
0 commit comments