如何关闭 VS Code 中自动删除未使用的导入?

问题描述 投票:0回答:2

VS Code 会自动删除未使用的导入,更烦人的是,它会删除已使用但已注释掉的导入。例如,如果我要保存这段代码:

from pprint import pprint
# pprint("foo")

它将删除第一行。那么我该如何关闭此功能,因为它不断迫使我重写导入?

python visual-studio-code import
2个回答
5
投票

检查您的

settings.json
(User and Workspace) 是否有以下设置,删除此配置或将其更改为
false

    "editor.codeActionsOnSave": {
        "source.fixAll": true,
    },

0
投票

在设置中搜索“editor.codeActionsOnSave”。点击“在settings.json中编辑”

"editor.codeActionsOnSave": {
    "source.organizeImports": "never"
},
© www.soinside.com 2019 - 2024. All rights reserved.