VS Code 的 Pylance 扩展通过更深入地理解 Python 改进自动缩进功能!此功能使您可以更多地关注代码的逻辑,而不是格式化。在 VS Code Insiders 中使用 Python 扩展的预发布版本来尝试这个功能!您可以通过验证用户 settings.json 文件中是否添加以下设置来判断它是否启用(View > Command Palette and run “Preferences: Open User
Settings (JSON)”):
"[python]": {
"editor.formatOnType": true,
},
在接下来的几个月里,我们将默认启用此设置。如果您有任何问题或反馈,请在 Pylance GitHub 存储库中告诉我们。
- https://code.visualstudio.com/insiders/?ocid=AID3052907
- https://github.com/microsoft/pylance-release
您现在可以尝试在浏览器中的 vscode.dev 中运行和调试 Python 代码!
有一个新的 VS 代码扩展,允许您尝试使用 WebAssembly 作为执行引擎在 Web 中运行 Python 代码。请注意,此扩展用于实验和研究目的,以了解使用 WebAssembly 在 Web 中运行 Python 代码,不应将其用于生产 Python 开发,因为这存在重大限制。
请按照以下步骤试用此预览:
打开基于 Chrome 的浏览器(例如 Microsoft Edge 或 Google Chrome)
使用 URL 模板URL https://insiders.vscode.dev/github/{username}/{repo}?vscode-coi= 导航到 GitHub 存储库;更换 {username} 和 {repo} 满足您的需求。如果需要,可以使用https://insiders.vscode.dev/github/dbaeumer/python-sample?vscode-coi= 。确保查询参数 ?vscode-coi= 附加到 URL
安装扩展的最新预发布版本 Experimental
- Python for the Web
打开一个 Python 文件
使用编辑器的运行菜单执行文件
使用相同的运行菜单调试 Python 文件
创建启动配置(例如)
{
"type": "python-web-wasm",
"name": "Debug Active Python File",
"request": "launch",
"program": "${file}",
"stopOnEntry": true,
"console": "integratedTerminal"
}
- https://devblogs.microsoft.com/python/python-in-visual-studio-code-december-2022-release/vscode.dev?ocid=AID3052907
-
Experimental - Python for the Web https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-python-web-wasm
@charliermarsh,ruff linter 的创建者,使用 Python 工具扩展模板创建了一个附带的 Ruff 扩展。这个 VS Code 扩展提供了对 Ruff linter 的支持,目前附带 ruff==0.0.138 。在 Visual Studio Code 中安装后,当您打开或编辑 Python 文件时,Ruff 将在您的代码上运行。支持包括替换 flake8 使用的 linting、使用 Organize Imports 的 isort 兼容导入排序、相当于 Ruff 的 --fix 支持的自动修复违规的“快速修复”操作,以及用于自动修复违规的 Fix all 命令。
此外,您可以通过在 settings.json 中启用 source.fixAll 操作,将 Ruff 配置为在保存时自动修复违规行为:
{
"editor.codeActionsOnSave": {
"source.fixAll": true
}
}
就像 Charlie 一样,您可以使用扩展模板来创建您自己喜欢的 linter 或格式化程序的 VS 代码扩展,并通过更改核心 Python 代码来实现!有关该模板的更多信息,请参考我们的2022年8月版本并尝试使用 Ruff 扩展!