使用 Pydev 开发时抑制警告 Eclipse

Suppress warning Eclipse when developing with Pydev

我想在定义装饰器时抑制 Eclipse 警告。

例如:

def tool_wrapper(func):
   def inner(self):
      cmd="test"
      cmd+=func(self)
   return inner

@tool_wrapper
def list_peer(self):
   return "testing "

我收到有关装饰器定义的警告: “方法 'tool_wrapper' 应该将 self 作为第一个参数

我在 class 中定义了装饰器,所以这是它正常工作的唯一方法。

谢谢

只需在 class 之外定义装饰器并将实例作为参数传递,它就可以正常工作。

def tool_wrapper(func):
    def inner(inst):  # inst : instance of the object
        cmd="test"
        cmd+=func(inst)
        return cmd
    return inner


class Test():

    def __init__(self):
        pass

    @tool_wrapper
    def list_peer(self):
        return "testing "


if __name__ == '__main__':
    t = Test()
    print t.list_peer()

此脚本打印 testtesting