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?
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).
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.
A proper treatment would require a type system for Python, which would be (is?) an interesting research problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With