Komodo Python auto complete: type inference with metadata variables?

I am using Komodo Edit for Python , and I want to get the most out of auto completion.

If I do this:

a = A() a. 

I can see the list of members A.

But if I do this:

 a = [A()] b = a[0] b. 

This does not work. I want to be able to do this:

 a = [A()] b = a[0] """b Type: A """ b. 

So, how can I say that auto is complete, that b is of type A?

+7
python autocomplete komodo
source share
2 answers

This does not answer your question, but with the Wing IDE you can give hints to the type analyzer with assert isinstance(b, A) . See here . I have not found a way to do this with Komodo, although perhaps this is when writing PHP or JavaScript.

Update

I found a way to trick Komodo into doing this:

 if 0: b=A() 

This works (at least on Komodo 5.2) and has no side effects, but be sure to confuse those who read your code.

+8
source share

I don't think you're lucky with that. The problem is that it is actually quite difficult to statically infer the type of variables in Python, except in the simplest case. Often the type is not known until runtime, so automatic completion is not possible.

The IDE does some static analysis to work out the obvious and best guesses, but I'm betting it doesn't even try to use elements in the container. Although we may decide that b is of type A , even small variations of your code can make it unrecognizable, especially since it is in a mutable container.

By the way, I tried this on the full Komodo platform, and it is not better. I heard that the Wing IDE has excellent code completion, but I'm not sure if it can do better either.

+3
source share

All Articles