summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2019-12-29 22:52:12 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2019-12-29 22:52:12 -0800
commitc54b3dd4620f9b3e7ac127c583ecb029fb90f1b7 (patch)
tree80ced7283e6e43c6359e17ecb1b7bd536a562aca
parent4edfd1d6c8ba741ac24594ff95847451b94db293 (diff)
downloadisort-c54b3dd4620f9b3e7ac127c583ecb029fb90f1b7.tar.gz
Fix support for multi-line comments ending in what appear to be comments
-rw-r--r--isort/api.py2
-rw-r--r--tests/test_isort.py25
2 files changed, 26 insertions, 1 deletions
diff --git a/isort/api.py b/isort/api.py
index 8d435b21..0aae7711 100644
--- a/isort/api.py
+++ b/isort/api.py
@@ -184,7 +184,7 @@ def sort_imports(
in_top_comment = False
first_comment_index_end = index - 1
- if not stripped_line.startswith("#") and '"' in line or "'" in line:
+ if (not stripped_line.startswith("#") or in_quote) and '"' in line or "'" in line:
char_index = 0
if first_comment_index_start == -1 and (
line.startswith('"') or line.startswith("'")
diff --git a/tests/test_isort.py b/tests/test_isort.py
index e5072b0f..451af9e2 100644
--- a/tests/test_isort.py
+++ b/tests/test_isort.py
@@ -4213,3 +4213,28 @@ import os
import sys
"""
assert SortImports(file_contents=test_input).output == test_input
+
+
+def test_comment_look_alike():
+ """Test to ensure isort will handle what looks like a single line comment
+ at the end of a multi-line comment.
+ """
+ test_input = '''
+"""This is a multi-line comment
+
+ending with what appears to be a single line comment
+# Single Line Comment"""
+import sys
+import os
+'''
+ assert (
+ SortImports(file_contents=test_input).output
+ == '''
+"""This is a multi-line comment
+
+ending with what appears to be a single line comment
+# Single Line Comment"""
+import os
+import sys
+'''
+ )