views:

230

answers:

3

Is it possible to use Ocaml/Haskell algorithm of type inference to suggest better autocompletions for Python?

The idea is to propose autocompletion for example in the following cases:

class A:
  def m1(self):
    pass
  def m2(self):
    pass

a = A()
a.     <--- suggest here 'm1' and 'm2'
fun1(a)

def fun1(b):
  b.   <--- suggest here 'm1' and 'm2'

Are there any good starting points?

+8  A: 

Excellent discussion, with many pointers, here (a bit dated). I don't believe any "production" editors aggressively try type-inferencing for autocomplete purposes (but I haven't used e.g. wingware's in a while, so maybe they do now).

Alex Martelli
+1: A lot of nice reading material at the link
ChristopheD
+1: that was the link i was going to post.
LB
A: 

A proper treatment would require a type system for Python, which would be (is?) an interesting research problem.

Don Stewart
+1  A: 

You could have a look at ECompletion and OCompletion in Pharo Smalltalk. The compromises will probably different for python, but educated guesses with some conservative type inference work in practice. It also depends if you want completion to replace browsing the code/documentation, or to assist typing and to avoid typos.

I think in Pharo, if the message is an explicit send to a class (SomeClass m) then of course it will propose all messages in that class and its superclasses. Else, it just guesses all methods names in the system that match the typed prefix, and that works well. OCompletion adds a bit of heuristic prioritization based on editing history.

Damien Pollet