Skip to content

Commit

Permalink
Fixed #1539: In extremely rare cases isort 5.5.4 introduces syntax er…
Browse files Browse the repository at this point in the history
…ror by removing closing paren.
  • Loading branch information
timothycrosley committed Oct 8, 2020
1 parent 2e02c19 commit c8d37de
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion isort/_version.py
@@ -1 +1 @@
__version__ = "5.5.4"
__version__ = "5.5.5"
5 changes: 3 additions & 2 deletions isort/core.py
Expand Up @@ -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 (
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -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 <timothy.crosley@gmail.com>"]
license = "MIT"
Expand Down
49 changes: 49 additions & 0 deletions tests/unit/test_regressions.py
Expand Up @@ -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
'''
)

0 comments on commit c8d37de

Please sign in to comment.