Python/Pycharm,Ctrl-Space 不调出代码补全 [英] Python/Pycharm, Ctrl-Space does not bring up code completion

查看:29
本文介绍了Python/Pycharm,Ctrl-Space 不调出代码补全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下文件.为什么当我在r."后按 Ctrl-Space 时代码完成不运行?它在红色框中显示没有建议".

I have the following file. Why does code completion not run when I press Ctrl-Space after the "r."? It says "no suggestion" in a red box.

(程序运行并输出:200)

(The program as it is runs and puts out: 200)

__author__ = 'hape'

import urllib.request
import urllib.response

print("Starting")
r = urllib.request.urlopen("http://www.python.org")

r.  <------------ No code completion, why not?!

print (r.getcode())

r.之后没有弹出代码补全,为什么?

After the r., code completion does not popup, why?

推荐答案

添加来自 JetBrains 的响应:@CrazyCoder 就在那里.问题是我们无法推断函数urllib.request.urlopen()"的正确返回类型,因为它的实现使用了一些我们无法静态处理的动态技巧,特别是:

Adding response from JetBrains: @CrazyCoder was right there. The problem is that we are not able to infer proper return type of the function "urllib.request.urlopen()" since its implementation uses some dynamic tricks that we cannot handle statically, in particular:

通常,我们会在 python-skeleton 中使用外部注释来处理诸如此类的困难情况,但它还不包含urllib.request"模块的类型提示.同样在即将发布的 PyCharm 版本中,我们计划切换到在 typeshed 项目中收集的注释集合.它发展得更加积极,并且已经包含一些urllib"的注释.要从中受益,您只需在解释器路径中的某处放置带有注释的urllib"包,以便 PyCharm 可以找到相应的 .pyi 存根.

Normally, we deal with difficult cases like that using external annotations in python-skeletons but it doesn't contain type hints for "urllib.request" module yet. Also in the upcoming versions of PyCharm we're planning to switch to the collection of annotations gathered in typeshed project. It evolves much more actively and already contains some annotations for "urllib". To benefit from them you just need to drop "urllib" package with annotations somewhere in your interpreter paths, so that PyCharm could find the respective .pyi stubs.

这篇关于Python/Pycharm,Ctrl-Space 不调出代码补全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆