summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2019-12-05 21:22:10 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2019-12-05 21:22:10 -0800
commit0c4c155fa4adc05bdb157cbcff12f17b3e4392e7 (patch)
tree15ebe64bdb58f2e95cf0d54edf102d1bba47c205
parentc805531052e7aa6ecceb595e134f76c68bae2902 (diff)
downloadisort-0c4c155fa4adc05bdb157cbcff12f17b3e4392e7.tar.gz
Only sort on sections that contain imports
-rw-r--r--isort/parse.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/isort/parse.py b/isort/parse.py
index 9c553643..f5c792d5 100644
--- a/isort/parse.py
+++ b/isort/parse.py
@@ -478,6 +478,7 @@ def identify_contiguous_imports(
in_quote: str = ""
first_comment_index_start: int = -1
first_comment_index_end: int = -1
+ contains_imports: bool = False
for index, line in enumerate(input_stream):
if '"' in line or "'" in line:
char_index = 0
@@ -509,18 +510,20 @@ def identify_contiguous_imports(
import_section += line
elif stripped_line.startswith(IMPORT_START_IDENTIFIERS):
import_section += line
+ contains_imports = True
else:
not_imports = True
if not_imports:
if import_section:
- if not import_section.strip() or not ("from" in import_section or "import" in import_section):
+ if not contains_imports:
output_stream.write(import_section)
else:
for line in import_section.split(config.line_ending or '\n'):
output_stream.write("AN IMPORT")
output_stream.write(config.line_ending or '\n')
import_section = ""
+ contains_imports = False
output_stream.write(line)
not_imports = False