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

10,440

Solution 1

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.

Screen Shot from JB

Solution 2

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?

http://www.jetbrains.com/pycharm/webhelp/smart-type-code-completion-completing-code-based-on-type-information.html

Solution 3

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

Share:
10,440

Related videos on Youtube

Hartmut Pfarr
Author by

Hartmut Pfarr

Updated on June 17, 2022

Comments

  • Hartmut Pfarr
    Hartmut Pfarr about 2 years

    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?

    • CrazyCoder
      CrazyCoder over 11 years
      PyCharm doesn't know the type of r as the library has no type hints for urlopen.
    • EML
      EML over 11 years
      @CrazyCoder has the answer here. A quick and dirty solution to the issue is to put an import pdb; pdb.set_trace() at the line in question, and in the debugger terminal enter dir(r) to reveal the attributes of the r object.
    • CrazyCoder
      CrazyCoder over 11 years
      PyCharm 2.7 will use runtime information from the debugger for type hints.