求助关于 mypy 的问题

2019-08-08 14:25:03 +08:00
 thuwskdsgcf

如下一段的 python 代码,这个方法的返回类型应该写点什么

def aa(num: int) -> ??:
    if num > 0:
        return True, {'num': num}
    return False, ''

我试过Tuple[bool, Union[str, Dict[str, int]]], vscode 提示不正确

1359 次点击
所在节点    Python
2 条回复
zidy111
2019-08-09 11:54:43 +08:00
贴一下你 vscode 的 setting.json,
用 mypy 检查是没有报错的上面的返回值是没有问题的
thuwskdsgcf
2019-08-12 14:36:29 +08:00
@zidy111 这是 user settings
{
"files.autoSave": "off",
"angular-schule.configUpdated": "0.4.6",
"terminal.integrated.fontFamily": "Consolas, 'Meslo LG M for Powerline'",
"breadcrumbs.enabled": true,
"python.formatting.provider": "yapf",
"editor.fontFamily": "Consolas",
"editor.fontSize": 14,
"python.jediEnabled": false,
"terminal.integrated.fontSize": 14,
"terminal.integrated.macOptionClickForcesSelection": true,
"terminal.integrated.lineHeight": 1.2,
"editor.fontWeight": "600",
"files.associations": {
"*.html": "html"
},
"debug.toolBarLocation": "docked",
"leetcode.endpoint": "leetcode-cn",
"git.autofetch": true,
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"python.linting.mypyEnabled": true,
"window.zoomLevel": 0,
"workbench.iconTheme": "vscode-icons",
"files.exclude": {
"**/__pycache__": true,
"**/.classpath": true,
"**/.factorypath": true,
"**/.project": true,
"**/.settings": true,
"**/*.pyc": true
},
"terminal.external.osxExec": "iTerm.app",
"terminal.integrated.enableBell": true,
"terminal.integrated.macOptionIsMeta": true,
"workbench.colorTheme": "Monokai Pro"
}

这是 workspace settings
{
"python.pythonPath": "/Users/chenkun/.local/share/virtualenvs/InfinityStones-TeHFX75W/bin/python",
"python.linting.pylintArgs": [
"--load-plugins",
"pylint_django",
"--disable=C0103",
"--disable=C0111",
"--disable=C0301"
],
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"files.exclude": {
"**/surface/static": true
}
}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/590143

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX