Pydev代码完成一切 [英] Pydev Code Completion for everything

查看:104
本文介绍了Pydev代码完成一切的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多情况下(如函数参数) Pydev 不会静态地知道变量的类型。因此,代码完成(或使用 ctrl + space 之后)不起作用。

In many cases (such as function parameters) Pydev doesn't statically know the type of a variable. Therefore code completion (after . or when using ctrl+space) doesn't work.

在大多数情况下,您在设计软件时,您知道在运行时将会是什么类型的。有没有办法提示Pydev正确地完成代码?

In most cases, you know what type will be in run-time as you are designing the software. Is there a way to hint Pydev to code completing it correctly?

我想这可能需要一个特定的Pydev功能,甚至可能需要一个新的Python PIP。

I guess this may require a specific Pydev feature, or perhaps even a new Python PIP.

这实际上似乎是所有动态语言的一般问题...

This is actually seems to be a generic problem with all dynamic languages...

更新:

可能有一个例子来澄清:

UPDATE:
Perhaps an example is in place for clarification:

def some_func(a_list, an_object):
    a_list.app        # Here I would not get code completion for append

如果Pydev(或PIP)支持它,则可以工作:

An example of something that could work, if Pydev (or a PIP) would support it:

from someobj import SomeObject
def some_func(a_list, an_object):
    # typecast: a_list=list
    # typecast: an_object=SomeObject
    a_list.app        # Now code completion would show append

我不认可这种具体方法 - 这只是一个可以工作的系统的例子。再次,当然这不应该是强制性的 - 但是有时候缺少提示类型的可能性是令人讨厌的。

I'm not endorsing this specific method - it's just an example of a system that could work. Again, of course this should not be mandatory - but sometimes the lack of the possibility to hint the type is annoying.

推荐答案

由于PyDev 2.8.0,它可以使用docstrings和comment来发现对象的类型。

Since PyDev 2.8.0, it can use docstrings and comments to discover the type of objects.

请参阅: http://pydev.org/manual_adv_type_hints

See: http://pydev.org/manual_adv_type_hints.html for details on the supported formats.

[PyDev 2.8.0之前]

以前,它只支持assert isinstance调用(这仍然有效):

Previously, it only supported assert isinstance calls (and this still works):

assert isinstance(a_list, list)

PyDev将能够识别它并正确提供代码完成(请注意你可以运行Python,而不用断言,如果你发现它使你的代码变慢: Python优化(-O或PYTHONOPTIMIZE)做什么?

PyDev will be able to recognize it and properly provide code-completion for it (note that you can run Python without the assertions later on if you find it's making your code slower: What does Python optimization (-O or PYTHONOPTIMIZE) do? )

这篇关于Pydev代码完成一切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆