Komodo Python 自动完成:通过变量元数据进行类型推断? [英] Komodo Python auto complete: type inference by variable metadata?
问题描述
我正在使用 Komodo Edit 进行 Python 开发,我想充分利用自动完成功能.
I'm using Komodo Edit for Python development, and I want to get the best out of the auto complete.
如果我这样做:
a = A()
a.
我可以看到 A 的成员列表.
I can see a list of members of A.
但是如果我这样做:
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.
那么我如何告诉自动完成 b 是 A 类型?
So how can I tell the auto complete that b is of type A?
推荐答案
这并不能真正回答您的问题,但使用 Wing IDE 您可以使用 assert isinstance(b, A)
向类型分析器提供提示.请参阅此处.我还没有找到用 Komodo 做到这一点的方法,虽然显然它是 可能 编写 PHP 或 JavaScript 时.
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.
更新:
我找到了一种方法来欺骗 Komodo:
I've found a way to trick Komodo into doing this:
if 0: b=A()
这有效(至少在 Komodo 5.2 上)并且没有副作用,但肯定会让阅读您代码的人感到困惑.
This works (at least on Komodo 5.2) and has no side effects, but is sure to confuse whoever reads your code.
这篇关于Komodo Python 自动完成:通过变量元数据进行类型推断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!