Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
530 views
in Technique[技术] by (71.8m points)

autocomplete - Komodo Python auto complete: type inference by variable metadata?

I'm using Komodo Edit for Python development, and I want to get the best out of the auto complete.

If I do this:

a = A()
a.

I can see a list of members of A.

But if I do this:

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

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

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

Type: A
"""
b.

So how can I tell the auto complete that b is of type A?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This doesn't really answer your question, but with Wing IDE you can give hints to the type analyzer with assert isinstance(b, A). See here. I haven't found a way to do it with Komodo, though apparently it's possible when writing PHP or JavaScript.

Update:

I've 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 is sure to confuse whoever reads your code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...