V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
thuwskdsgcf
V2EX  ›  Python

求助关于 mypy 的问题

  •  
  •   thuwskdsgcf · 2019-08-08 14:25:03 +08:00 · 1416 次点击
    这是一个创建于 1959 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    2 条回复    2019-08-12 14:36:29 +08:00
    zidy111
        1
    zidy111  
       2019-08-09 11:54:43 +08:00
    贴一下你 vscode 的 setting.json,
    用 mypy 检查是没有报错的上面的返回值是没有问题的
    thuwskdsgcf
        2
    thuwskdsgcf  
    OP
       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
    }
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3174 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 12:52 · PVG 20:52 · LAX 04:52 · JFK 07:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.