我正在尝试让 autopep8 正常工作,以 2 个空格而不是 4 个空格正确缩进 Python 代码。我正在使用带有 Python 扩展的 VS Code,该扩展使用 autopep8 进行格式化。我发现here https://stackoverflow.com/questions/35531080/how-do-i-auto-indent-python-code-in-visual-studio-codeautopep8 可以配置为使用 2 个空格
"python.formatting.autopep8Args": ["--indent-size=2"]
但这对我不起作用。
我的情况是这样的。当我按 Enter 时,它会正确地开始下一行,其缩进与上一行相同。在左括号后按 Enter 键,它会正确地以 2 个空格开始新行。但是当我粘贴或保存时(我将“editor.formatOnPaste”和“editor.formatOnSave”设置为true),烦人的事情发生了:括号内的所有2空格缩进变成了4(其他2空格缩进不受影响) 。为什么要这样做?我怎样才能让它到处都是 2 个空格?
====编辑====
我发现 pylint 错误Wrong hanging indentation (remove 2 spaces). [bad-continuation]
。这是因为我的 pylintrc 有indent-after-paren=2
。我想知道 autopep8 或其他 Python 格式化程序是否可以设置此属性?
Adding --indent-size=2 --ignore=E121
worked for me.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)