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)
在这种情况下如何使用自动完成功能?
谢谢。答案 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)