I would like to understand what is going on in PyCharm with Inferred type in the Quick Documentation window.
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
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
?
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. To be fixed in 2016.2 release.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.