File tree Expand file tree Collapse file tree 2 files changed +35
-12
lines changed Expand file tree Collapse file tree 2 files changed +35
-12
lines changed Original file line number Diff line number Diff line change @@ -61,10 +61,9 @@ def add_future(node, symbol):
61
61
import_ = fixer_util .FromImport ('__future__' ,
62
62
[Leaf (token .NAME , symbol , prefix = " " )])
63
63
64
- # If we're inserting as the first element, ensure any shebang prefix is maintained.
65
- if idx == 0 and node .prefix .startswith ('#!' ):
66
- import_ .prefix = node .prefix
67
- node .prefix = ''
64
+ # Place after any comments or whitespace. (copyright, shebang etc.)
65
+ import_ .prefix = node .prefix
66
+ node .prefix = ''
68
67
69
68
children = [import_ , fixer_util .Newline ()]
70
69
root .insert_child (idx , Node (syms .simple_stmt , children ))
Original file line number Diff line number Diff line change 30
30
""" )
31
31
32
32
DOCSTRING = ("""\
33
- \" \" \ "
33
+ \" " "
34
34
Docstring
35
- \" \" \ "
35
+ \" " "
36
36
import foo
37
37
""" , """\
38
- \" \" \ "
38
+ \" " "
39
39
Docstring
40
- \" \" \ "
40
+ \" " "
41
41
from __future__ import absolute_import
42
42
import foo
43
43
""" )
53
53
54
54
DOCSTING_AND_SHEBANG = ("""\
55
55
#!/usr/bin/env python
56
- \" \" \ "
56
+ \" " "
57
57
Docstring
58
- \" \" \ "
58
+ \" " "
59
59
import foo
60
60
""" , """\
61
61
#!/usr/bin/env python
62
- \" \" \ "
62
+ \" " "
63
63
Docstring
64
- \" \" \ "
64
+ \" " "
65
65
from __future__ import absolute_import
66
66
import foo
67
67
""" )
85
85
import foo
86
86
""" )
87
87
88
+
89
+ COPYRIGHT_AND_DOCSTRING = ("""\
90
+ #
91
+ # Copyright notice
92
+ #
93
+
94
+ \" ""Docstring\" ""
95
+
96
+ import foo
97
+ """ , """\
98
+ #
99
+ # Copyright notice
100
+ #
101
+
102
+ \" ""Docstring\" ""
103
+
104
+ from __future__ import absolute_import
105
+ import foo
106
+ """ )
107
+
108
+
88
109
def test_no_imports ():
89
110
check_on_input (* NO_IMPORTS )
90
111
@@ -108,3 +129,6 @@ def test_import_with_docstring_and_shebang():
108
129
109
130
def test_import_with_copyright_and_shebang ():
110
131
check_on_input (* COPYRIGHT_AND_SHEBANG )
132
+
133
+ def test_import_with_copyright_and_docstring ():
134
+ check_on_input (* COPYRIGHT_AND_DOCSTRING )
You can’t perform that action at this time.
0 commit comments