提交 6988259a 编辑于 作者: Timothy Crosley's avatar Timothy Crosley
浏览文件

Save progress on fixing 1321

无相关合并请求
显示 18 个添加2 个删除
+18 -2
......@@ -413,6 +413,7 @@ def _with_from_imports(
and parsed.imports[section]["from"][module][from_import]
)
):
#breakpoint()
from_import_section.append(from_imports.pop(0))
if star_import:
import_statement = import_start + (", ").join(from_import_section)
......
......@@ -322,6 +322,7 @@ def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedConte
nested_module = just_imports[as_index - 1]
module = just_imports[0] + "." + nested_module
as_name = just_imports[as_index + 1]
categorized_comments["nested"].setdefault(just_imports[0], {})[nested_module] = ", ".join(comments)
if nested_module == as_name and config.remove_redundant_aliases:
pass
elif as_name not in as_map["from"][module]:
......@@ -333,9 +334,9 @@ def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedConte
pass
elif as_name not in as_map["straight"][module]:
as_map["straight"][module].append(as_name)
if not config.combine_as_imports:
categorized_comments["straight"][module] = comments
comments = []
comments = []
del just_imports[as_index : as_index + 2]
if type_of_import == "from":
import_from = just_imports.pop(0)
......
......@@ -427,3 +427,17 @@ import logging
from ast import excepthandler
"""
)
def test_losing_comments_when_combine_as_is_set_issue_1321():
"""Tests to ensure isort doesn't remove comments information when used in conjunction with
combine_as_imports.
See: https://github.com/timothycrosley/isort/issues/1321
"""
assert isort.check_code(
"""from foo import * # noqa
from foo import bar as quux # noqa
""",
show_diff=True,
combine_as_imports=True,
)
支持 Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册