Search code examples
pythoneclipsedecoratorpydev

Suppress warning Eclipse when developing with Pydev


I want to suppress Eclipse warnings when defining decorators.

For example:

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

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

I get warning on a decorator definition: "Method 'tool_wrapper' should have self as first parameter

I define the decorator inside a class, so this is the only way it's working properly.

Thanks


Solution

  • Just define your decorator outside the class and pass the instance as an argument, it will work just as fine.

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

    This script prints testtesting