简体   繁体   English

理解Pycharm推断类型提示

[英]Understanding Pycharm inferred type hinting

I would like to understand what is going on in PyCharm with Inferred type in the Quick Documentation window. 我想在“快速文档”窗口中了解PyCharm中带有推断类型的内容。

Using the function below, I see the following in Quick Documentation: 使用下面的功能,我在快速文档中看到以下内容: 快速编辑窗口

Argument host appears as Optional[str] as I expect it to, but auth and version only show str | None 参数host显示为我期望的Optional[str] ,但authversion仅显示str | None str | None . str | None Technically (I believe) both are correct, but why the discrepancy between these similar arguments? 技术上(我相信)两者都是正确的,但为什么这些类似论点之间存在差异?

You'll notice I tried altering the type hint for version just to see if that made any difference. 你会注意到我试图改变版本的类型提示只是为了看看是否有任何区别。

Am I missing something about how type hinting works? 我错过了类型提示的工作原理吗?
Is there some way I can get Optional[str] to display for auth and version ? 有什么方法我可以获得Optional[str]显示authversion

def getBaseUrl(service, host=None, auth=None, version=None):
    """
    Defaulted arguments will automatically fetch the values from config 

    :param str service: wms, wfs
    :param str or None host:    [internal | external | {user submitted host}] -
                                internal and external will use the config file to automatically determine
                                anything else will be assumed as a server address including possible port.
    :param str or None auth:    basic, digest, oauth 
                                anything else will raise exception
    :param version: eg wms_v1, wfs_v1
    :type version:  str or None
    :return: base url for use in the gis Webservice
    """
    assert service.lower() == 'wms' or service.lower() == 'wfs', "Unsupported service: %s" % service

    internalhost = cfg.get('GIS', 'internalhost')
    externalhost = cfg.get('GIS', 'externalhost')

    if host is None:
        host = cfg.get('GIS', 'host')
    if version is None:
        version = cfg.get(service, 'version')

    if host == "internal":
        host = "{host}".format(host=internalhost)

    elif host == 'external':
        host = "{host}".format(host=externalhost)

    else:
        host = "{host}".format(host=host)

    return buildBaseUrl(host=host, version=version, auth=auth, service=service)

Looks like this is indeed a bug with Pycharm. 看起来这确实是Pycharm的一个错误。 To be fixed in 2016.2 release. 待修订于2016.2发布。

https://youtrack.jetbrains.com/issue/PY-17705 https://youtrack.jetbrains.com/issue/PY-17705

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM