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