Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...