Python/Pycharm, Ctrl-Space does not bring up code completion

别来无恙 提交于 2019-11-30 16:12:09
Amod

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:

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.

Check whether the IDE is in Power Saving Mode. If it is, then no code completion process or any any other background process works

It shows about it in the status bar at the bottom of the IDE

@CrazyCoder was right.Fow now, Pycharm does not kown the type of r.

If you really like to auto completion, first get the type of r using IPython or debug

# IPython

In [1]: import urllib.request

In [2]: r = urllib.request.urlopen("http://www.python.org")

In [3]: type(r)
Out[3]: http.client.HTTPResponse

then use Python3 Annotations

r: http.client.HTTPResponse = urllib.request.urlopen("http://www.python.org")
r.  

Now, you can get

python annotation for http.client.HTTPResponse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!