kimwz.kr
kimwz.kr

Reputation: 298

How can i use autocomplete in IDE in this case in python

class Event(object):
    can_i_autocomplete_this = True

class App(object):
    def decorator(self, func):
        self.func = func
    def call():
        self.func(Event())

app = App()

@app.decorator
def hello(something):
   print(something.can_i_autocomplete_this)

app.call()

I use decorator like this. but in this case, something parameter in hello method autocomplete doesn't work in IDE(pycharm). (must support python 2.7)

how can i use autocomplete in this case?

thank you.

Upvotes: 0

Views: 449

Answers (1)

user2235698
user2235698

Reputation: 7579

Usages of function are not analyzed in inferring types of parameters.

You could specify type of parameter inside doc:

@app.decorator
def hello(something):
    """
    :param something:
    :type something: Event
    :return:
    """
    print(something.can_i_autocomplete_this)

or using type hinting syntax (since Python 3.5):

@app.decorator
def hello(something: Event):
    print(something.can_i_autocomplete_this)

Upvotes: 2

Related Questions