diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c5ee4d73..a46e8e92a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,12 @@ Changelog NOTE: isort follows the [semver](https://semver.org/) versioning standard. Find out more about isort's release policy [here](https://pycqa.github.io/isort/docs/major_releases/release_policy/). +### 5.5.5 [Hotfix] October 7, 2020 + - Fixed #1539: isort 5.5.4 introduces syntax error by removing closing paren. + ### 5.5.4 [Hotfix] September 29, 2020 - Fixed #1507: in rare cases isort changes the content of multiline strings after a yield statement. - - Fixed #1505: Support case where known_SECTION points to a section not listed in sections. + - Fixed #1505: Support case where known_SECTION points to a section not listed in sections. ### 5.5.3 [Hotfix] September 20, 2020 - Fixed #1488: in rare cases isort can mangle `yield from` or `raise from` statements. diff --git a/isort/_version.py b/isort/_version.py index e82c92eb4..3a831202b 100644 --- a/isort/_version.py +++ b/isort/_version.py @@ -1 +1 @@ -__version__ = "5.5.4" +__version__ = "5.5.5" diff --git a/isort/core.py b/isort/core.py index 696e5d751..558fc2adc 100644 --- a/isort/core.py +++ b/isort/core.py @@ -153,6 +153,7 @@ def process( in_top_comment = False first_comment_index_end = index - 1 + was_in_quote = bool(in_quote) if (not stripped_line.startswith("#") or in_quote) and '"' in line or "'" in line: char_index = 0 if first_comment_index_start == -1 and ( @@ -178,8 +179,8 @@ def process( break char_index += 1 - not_imports = bool(in_quote) or in_top_comment or isort_off - if not (in_quote or in_top_comment): + not_imports = bool(in_quote) or was_in_quote or in_top_comment or isort_off + if not (in_quote or was_in_quote or in_top_comment): if isort_off: if stripped_line == "# isort: on": isort_off = False diff --git a/pyproject.toml b/pyproject.toml index 75fb08633..e9b1fdc49 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ line-length = 100 [tool.poetry] name = "isort" -version = "5.5.4" +version = "5.5.5" description = "A Python utility / library to sort Python imports." authors = ["Timothy Crosley "] license = "MIT" diff --git a/tests/unit/test_regressions.py b/tests/unit/test_regressions.py index 78888c409..09d4302d1 100644 --- a/tests/unit/test_regressions.py +++ b/tests/unit/test_regressions.py @@ -1121,3 +1121,52 @@ def d(): ''', show_diff=True, ) + + +def test_isort_shouldnt_introduce_syntax_error_issue_1539(): + """isort should NEVER introduce syntax errors. + In 5.5.4 some strings that contained a line starting with from could lead to no empty paren. + See: https://github.com/PyCQA/isort/issues/1539. + """ + assert isort.check_code( + '''"""Foobar + from {}""".format( + "bar", +) +''', + show_diff=True, + ) + assert isort.check_code( + '''"""Foobar + import {}""".format( + "bar", +) +''', + show_diff=True, + ) + assert ( + isort.code( + '''"""Foobar + from {}""" + from a import b, a +''', + ) + == '''"""Foobar + from {}""" + from a import a, b +''' + ) + assert ( + isort.code( + '''"""Foobar + from {}""" + import b + import a +''', + ) + == '''"""Foobar + from {}""" + import a + import b +''' + )