英文:
Different results running Black formatter standalone vs. from PyDev
问题
当我在PyDev中以可执行文件路径配置运行Black格式化程序(在保存文件时),它会在函数周围插入空行,但当我从命令行运行相同的可执行文件时,它不会这样做。两种调用都使用相同的pyproject.toml文件。有任何想法为什么会发生这种情况吗?
编辑:问题中的文件是一个.pyi文件。
英文:
When I run Black formatter (configured as a path to the executable) on file save in PyDev it inserts empty lines around functions, but when I run the same executable from command line it does not. Both invocations are using the same pyproject.toml file. Any ideas why this can be happening?
EDIT: the file in question is a .pyi file
答案1
得分: 1
我认为我知道发生了什么。Black使用不同的规则来格式化.pyi文件,我窥探了PyDev,并且看起来它在临时文件上运行Black,所以我认为发生的情况是它丢失了pyi扩展名,而Black将临时文件视为普通的py文件。VSCode曾经有过类似的问题:https://github.com/microsoft/vscode-python/issues/13341
看起来是PyDev的一个bug。
英文:
I think I know what's happening. Black uses different rules for formatting .pyi files, I peeked inside PyDev and it looks like it runs Black on a temp file, so I think what's happening is that it loses the pyi extension and Black treats the temp file as a normal py file. VSCode had a similar issue: https://github.com/microsoft/vscode-python/issues/13341
Seems like a PyDev bug.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论