Python / Pycharm, Ctrl-Space does not cause code completion

I have the following file. Why does code completion fail when I Ctrl-Space after "r."? The red box says "no offer."

(The program starts and issues: 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 r. code completion does not appear, why?

+3
python pycharm code-completion
source share
4 answers
+3
source share

Adding a response from JetBrains: @CrazyCoder was there. The problem is that we cannot deduce the correct return type of the function "urllib.request.urlopen ()", because its implementation uses some dynamic tricks that we cannot handle statically, in particular:

We usually look at complex cases like using external annotations in python-skeletons, but there are no type hints for the urllib.request module yet. Also in future versions of PyCharm we plan to switch to a collection of annotations collected in a type project. It is developing much more actively and already contains some annotations for "urllib". To capitalize on them, you just need to drop the β€œurllib” package with annotations somewhere in your interpreter paths so that PyCharm can find the appropriate .pyi stubs.

JB screen shot

+3
source share

Check if the IDE is in power saving mode. If so, then the code completion process or some other background process does not work

This appears in the status bar at the bottom of the IDE

+1
source share

@CrazyCoder was right. Now Pycharm does not specify type r .

If you really like autocomplete, first enter type 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

0
source share

All Articles