Skip to content Skip to sidebar Skip to footer

Autocompletion In PyCharm Based On Type

I'm using PyCharm for python coding. The autocompletion in PyCharm is not as good as in IntelliJ (Java). Consider the below code a = [1,2,3,4] a. In this case, after I press the d

Solution 1:

Yes, Python 3.5 introduces type hinting and Pycharm utilizes that.

Use

def func_name(param: type) -> return_type:

Like

def func_a(a: list):

Note that all type hints are completely optional and ignored by the interpreter. However, Pycharm can potentially help you detect type errors if you use it as a habit.


Solution 2:

This might not answer your question but this will be helpful for those who just started using pycharm for Django application.

PyCharm does not give (It underlines some built in functions with red) auto-completion option for Django if you have started project with Pure Python. Pure Python option comes when you click on new project option from file menu or when you run pycharm to start new project. Pure Python is the default selected option on new project page. You should choose Django (the 2nd option) to get auto-completion option in PyCharm.

Hope this would be helpful for others.


Solution 3:

Can do : (examples using list):

def func_a(a:list):
    do_this()

Or manually check:

def func_a(a):
    if isinstance(a,list):
        do_this
    else:

        raise TypeError("expected type of 'list' but got type of '%s'"%type(a).__name__)        

Post a Comment for "Autocompletion In PyCharm Based On Type"