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.
(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())
After the r.
, code completion does not popup, why?
Have you looked at the Pycharm page for Editor code completion settings?
http://www.jetbrains.com/pycharm/webhelp/editor-code-completion.html
By Enabling Smart Type code completion?
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
来源:https://stackoverflow.com/questions/14611714/python-pycharm-ctrl-space-does-not-bring-up-code-completion