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
255 views
in Technique[技术] by (71.8m points)

python - Pydev Code Completion for everything

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.

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?

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

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.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

[Edit]

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

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

[Before PyDev 2.8.0]

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

assert isinstance(a_list, list)

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? )


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

...