Skip to content
GitLab
探索
项目
群组
代码片段
项目
群组
代码片段
/
帮助
帮助
支持
社区论坛
快捷键
?
提交反馈
登录
切换导航
菜单
打开侧边栏
ExternalRepo
isort
提交
6988259a
提交
6988259a
编辑于
4年前
作者:
Timothy Crosley
浏览文件
操作
下载
电子邮件补丁
差异文件
Save progress on fixing 1321
上级
9b0fd439
issue/1321/combine_as_comments
无相关合并请求
变更
3
Hide whitespace changes
Inline
Side-by-side
显示
3 个更改的文件
isort/output.py
+1
-0
isort/output.py
isort/parse.py
+3
-2
isort/parse.py
tests/test_regressions.py
+14
-0
tests/test_regressions.py
有
18 个添加
和
2 个删除
+18
-2
isort/output.py
+
1
-
0
浏览文件 @
6988259a
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
isort/parse.py
+
3
-
2
浏览文件 @
6988259a
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_regressions.py
+
14
-
0
浏览文件 @
6988259a
...
...
@@ -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
,
)
This diff is collapsed.
Click to expand it.
编辑
预览
支持
Markdown
0%
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
菜单
探索
项目
群组
代码片段