Pydev Code Completion for everything

瘦欲@ 提交于 2019-11-29 03:01:39
Fabio Zadrozny

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

As of PyDev 2.8.0 can use Sphinx or Epydoc comments for code completion: http://pydev.org/manual_adv_type_hints.html

If you use PyCharm, you can pick either epydoc or sphinx docstring style and specify types of parameters and function return values according to that style (further discussion)

Zoran Pavlovic

What I usually do to circumvent this.

def func(my_list_param):
    my_list_param = []
    my_list_param.appe # at this stage I would get code completion.

Just remember to delete the variable initialization when testing or committing. Oh and btw, the response marked as an answer doesn't seem to work for me.

If you are using Python >= 3.5 in your code you can specify parameters type in function declarations (26.1. typing — Support for type hints), so you code could be:

from someobj import SomeObject

def some_func(a_list: list, an_object: SomeObject):
    a_list.app           # Code completion works
    an_object.a_method() # Code completion works

This type of syntax, has no effects on execution and does not make any check on the real type passed o the function, but make your code more readable and makes the code completion work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!