From c54b3dd4620f9b3e7ac127c583ecb029fb90f1b7 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sun, 29 Dec 2019 22:52:12 -0800 Subject: Fix support for multi-line comments ending in what appear to be comments --- isort/api.py | 2 +- tests/test_isort.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) 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 +''' + ) -- cgit v1.2.1