在python中如何在IDE中使用自动完成功能

时间:2016-08-26 10:54:06

标签: python autocomplete pycharm python-decorators

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

我像这样使用装饰器。 但在这种情况下,hello方法自动完成中的something参数在IDE(pycharm)中不起作用。 (必须支持python 2.7)

在这种情况下如何使用自动完成功能?

谢谢。

1 个答案:

答案 0 :(得分:2)

在推断参数类型时不分析函数的用法。

您可以在doc:

中指定参数类型
@app.decorator
def hello(something):
    """
    :param something:
    :type something: Event
    :return:
    """
    print(something.can_i_autocomplete_this)

或使用类型提示语法(自Python 3.5起):

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