Skip to content

Commit

Permalink
Fix iteration
Browse files Browse the repository at this point in the history
Signed-off-by: Gaetan Semet <gaetan@xeberon.net>
  • Loading branch information
gsemet committed Apr 3, 2016
1 parent 9655eeb commit af5033b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
13 changes: 10 additions & 3 deletions fiximports/fiximports.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import argparse
import re
import sys
import six


class FixImports(object):
Expand Down Expand Up @@ -105,11 +106,17 @@ def maybeEndGroup():
self.group_start = None

if splitImportStatements:
for line in lines:
iter = six.next(lines)
while True:
line = line.strip()
try:
line = six.next()
except StopIteration:
break
if self.isImportLine(line):
# join any continuation lines (\\)
while line[-1] == '\\':
line = line[:-1] + iter.__next__()
line = line[:-1] + six.next()
if self.group_start is None:
self.group_start = len(newlines)

Expand All @@ -119,7 +126,7 @@ def maybeEndGroup():
module = match.group(1)
imports = [s.strip() for s in match.group(2).split(",")]
for imp in imports:
newlines.append("from %s import %s" % (module, imp))
newlines.append("from {} import {}".format(module, imp))
continue
else:
maybeEndGroup()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
setuptools>=17.1
pip>=1.0
argparse; python_version=='2.6'
six>=1.10.0

0 comments on commit af5033b

Please sign in to comment.