我如何设置“组织进口”将每个导入到新线上

发布于 2025-01-27 09:53:49 字数 299 浏览 1 评论 0原文

我希望每个导入在同一行上从同一软件包中导入,而要避免合并冲突。但是,当我按 shift + alt + o 时,它将所有导入都放在支架之间的相同行上。有没有办法自定义此快捷方式,以便将每个导入都放在单独的线上?

例如,

from typing import Dict, List, Tuple, Union

我不想拥有

from typing import Dict
from typing import List

等。

Instead of having imports from the same package on the same line I would like each import to be on a separate line to avoid merge conflicts. When I press Shift + Alt + O however, it puts all the imports on the same line between brackets. Is there a way to customise this shortcut so that it puts each import on a separate line?

e.g. instead of having

from typing import Dict, List, Tuple, Union

I would like to have

from typing import Dict
from typing import List

etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回眸一遍 2025-02-03 09:53:50

在幕后,组织python的导入使用isort。通过查看

--multi-line 7 --sl

随之而来的是,您可以转到设置,搜索python>排序导入:args,并添加以下内容:

"python.sortImports.args": [
  "--multi-line",
  "7",
  "--sl"
]

Behind the scenes, Organize Imports for python uses isort. By looking at isort's command line arguments, we see that you can achieve this functionality by adding the following arguments:

--multi-line 7 --sl

With that said, you can go to your settings, search for Python > Sort Imports: Args, and add the following:

Sort Imports Args

Or you can manually add the entry in settings.json:

"python.sortImports.args": [
  "--multi-line",
  "7",
  "--sl"
]
隱形的亼 2025-02-03 09:53:50

isort -sl。这应该足够了。

  --sl, --force-single-line-imports
                        Forces all from imports to appear on their own line

isort --sl . This should be enough.

  --sl, --force-single-line-imports
                        Forces all from imports to appear on their own line
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文