Code completion barely works

Say I'm working with the 'requests' python library.
req = requests.get("")

Now after this, if I type 'req.', I'm supposed to get a list of all methods I can access. But for some reason I don't, even if I manually press ctrl-space.

If I try this in ipython, I get autocomplete recommendations. Even if I try it via the built in python console in pycharm, I get recommendations.

Why's this happening? I'm very underwhelmed by Pycharm because of this. Hope this isn't normal behavior.
Comment actions Permalink
Python is a dynamically typed language, which means that the "get" function does not declare its return type. When you're entering code in IPython or in the PyCharm console, the code is actually being executed, and it's possible to inspect the object instance in the running interpreter and to get the list of its methods. When you're entering code in PyCharm or in any other Python IDE, it is not executed, and it's only possible to use static analysis to infer the return type of the method. This is not possible in all cases.
Comment actions Permalink
Also, please avoid cross-posting the same question to multiple forums.
Comment actions Permalink

this also happens even when the function returning the object can only create one type, pycharm knows this since during thath auto -completion I am shown the type that function will return, but then whether I assign the result of the function to a variable or follow up directly with a dot pycharm can't auto-complete that function.

for instance:



object = MySingletonClass.getInstance()


won't auto-complete someFunction().

even though this does work:

object = MyRegularClass()


does auto-complete someFunction().

pycharm can apparently keep track of the type of some objects but once instantiated like this don't get that treatment?


the dynamically typed argument goes out of the window when pycharm

  1. does know the return type of the function
  2. does know the type of a dynamic object if only it is instantiated in a different way.

Please sign in to leave a comment.