【问题标题】:How can i use autocomplete in IDE in this case in python在这种情况下,如何在 python 中使用 IDE 中的自动完成功能
【发布时间】:2017-01-03 00:37:43
【问题描述】:
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)

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

谢谢。

【问题讨论】:

标签: python autocomplete pycharm python-decorators


【解决方案1】:

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

您可以在文档中指定参数类型:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多