Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A python IDE with Code Completion including parameter-object-type inference

I have tested a variety of Python IDEs for their code completion capabilities. Does one exist that can do code completion in the following case:

def foo(x):
    print x.read()  // remove this line, and type in "print x."

def main():
    n = open("c:\\python27\\test.py");
    foo(n)

The IDE has to figure out that foo is invoked somewhere in the current module with a parameter which was return value from a call to open() which it would have to assume is a call to file.open, and thus, returns a file object. Thus, x. followed by Ctrl+Space would invoke code completion and show that x, as a file object, can support any file object method, including read().

I have found that PyScripter, for example, can do this:

    n = open("c:\\python27\\test.py");
    n. // hit <ctrl+space> after n.

The above code completion scenario works because PyScripter does some special code completion logic to determine that n is a file object, but there doesn't appear to be a way to infer object types or available methods, from static analysis, that will deduce the types of parameters.

Secondly, if nothing like this is available in Python 2.x, in Python 3.x, now that there are static type hints, does any IDE support them?

   def foo(x:'file'):
        print x.read()  // remove this line, and type in "print x." and hit ctrl+space
like image 754
Warren P Avatar asked Oct 14 '11 14:10

Warren P


2 Answers

The only one I think can do (almost) that is PyCharm

But you must give it some hints:

Python2


If you're on Python 3, the IDE will check function annotations like that:

Python3

(The file class was removed from python 3 so I made an example with string)

It's not a free IDE but, IMHO has the best code completion available.

like image 105
JBernardo Avatar answered Oct 31 '22 20:10

JBernardo


WingIDE has such type inference as well, it's not open though.

like image 33
Johan Dahlin Avatar answered Oct 31 '22 21:10

Johan Dahlin