Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/1556/remove uneeded new line #1557

Merged
merged 3 commits into from Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,9 @@ 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.6.4 October TBD, 2020
- Fixed #1556: Empty line added between imports that should be skipped.

### 5.6.3 October 11, 2020
- Improved packaging of test files alongside source distribution (see: https://github.com/PyCQA/isort/pull/1555).

Expand Down
35 changes: 27 additions & 8 deletions isort/parse.py
Expand Up @@ -218,17 +218,36 @@ def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedConte
import_index = index - 1
while import_index and not in_lines[import_index - 1]:
import_index -= 1
elif "isort:skip" in line or "isort: skip" in line:
commentless = line.split("#", 1)[0]
else:
commentless = line.split("#", 1)[0].strip()
if (
"(" in commentless
and not commentless.rstrip().endswith(")")
and import_index < line_count
("isort:skip" in line or "isort: skip" in line)
and "(" in commentless
and ")" not in commentless
):
import_index = index
while import_index < line_count and not commentless.rstrip().endswith(")"):
commentless = in_lines[import_index].split("#", 1)[0]
import_index += 1

starting_line = line
while "isort:skip" in starting_line or "isort: skip" in starting_line:
commentless = starting_line.split("#", 1)[0]
if (
"(" in commentless
and not commentless.rstrip().endswith(")")
and import_index < line_count
):

while import_index < line_count and not commentless.rstrip().endswith(
")"
):
commentless = in_lines[import_index].split("#", 1)[0]
import_index += 1
else:
import_index += 1

if import_index >= line_count:
break
else:
starting_line = in_lines[import_index]

line, *end_of_line_comment = line.split("#", 1)
if ";" in line:
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/test_regressions.py
Expand Up @@ -1424,6 +1424,33 @@ def test_isort_shouldnt_split_skip_issue_1548():
)


def test_isort_shouldnt_split_skip_issue_1556():
assert isort.check_code(
"""
from tools.dependency_pruning.prune_dependencies import ( # isort:skip
prune_dependencies,
)
from tools.developer_pruning.prune_developers import ( # isort:skip
prune_developers,
)
""",
show_diff=True,
profile="black",
float_to_top=True,
)
assert isort.check_code(
"""
from tools.dependency_pruning.prune_dependencies import ( # isort:skip
prune_dependencies,
)
from tools.developer_pruning.prune_developers import x # isort:skip
""",
show_diff=True,
profile="black",
float_to_top=True,
)


def test_isort_losing_imports_vertical_prefix_from_module_import_wrap_mode_issue_1542():
"""Ensure isort doesnt lose imports when a comment is combined with an import and
wrap mode VERTICAL_PREFIX_FROM_MODULE_IMPORT is used.
Expand Down