menu Chancel's blog
rss_feed
Chancel's blog
有善始者实繁,能克终者盖寡。

VSCode设置Python的换行长度(2023年)

作者:Chancel Yang, 创建:2023-08-23, 字数:1214, 已阅:71, 最后更新:2023-08-24

这篇文章更新于 249 天前,文中部分信息可能失效,请自行甄别无效内容。

在2022年4月,vscode-python更新了说明如下

根据2022年4月的公告,我们的团队一直在努力将我们在Visual Studio Code的Python扩展中提供的工具支持分解为单独的扩展,以提高性能、稳定性,并不再需要在Python环境中安装这些工具 - 因为它们可以与扩展一起提供。这还允许在相应工具的新版本可用时,将这些扩展单独发布,与Python扩展分开发布。

参考官方公告:https://github.com/microsoft/vscode-python/wiki/Migration-to-Python-Tools-Extensions

以前用的格式化配置settings.json如下

JSON
{
    "files.exclude": {
        "**/.git": true,
        "**/.svn": true,``
        "**/.hg": true,
        "**/CVS": true,
        "**/__pycache__": true,
        "**/.DS_Store": true,
        "**/venv": true,
        "**/.pytest_cache": true
    },
    "python.formatting.provider": "yapf",
    "python.formatting.yapfArgs": [
        "--style={column_limit=256}"
    ],
}

这份配置现在会提示警告

Bash
This setting will soon be deprecated. 

Please use the Autopep8 extension or the Black Formatter extension.

Learn more here: https://aka.ms/AAlgvkb.

根据官方文档,可以自由选择pylintflake8autopep8等等,这里以Black Formatter为例,更新的settings.json如下

JSON
{
    ...
    "[python]": {
        "editor.defaultFormatter": "ms-python.black-formatter"
    },
    "black-formatter.args": [
        "--line-length=256"
    ]
}

所以只是格式稍微变动了下,废弃了python.formatting.provider,也不再要求python环境安装对应的格式化插件了


[[replyMessage== null?"发表评论":"发表评论 @ " + replyMessage.m_author]]

account_circle
email
web_asset
textsms

评论列表([[messageResponse.total]])

还没有可以显示的留言...
[[messageItem.m_author]] [[messageItem.m_author]]
[[messageItem.create_time]]
[[getEnviron(messageItem.m_environ)]]
[[subMessage.m_author]] [[subMessage.m_author]] @ [[subMessage.parent_message.m_author]] [[subMessage.parent_message.m_author]]
[[subMessage.create_time]]
[[getEnviron(messageItem.m_environ)]]