0

In the below code i am trying to apply the decorator on a class method. And i see the error as TypeError: myfunc() takes exactly 2 arguments (1 given) how to resolve this

    class mydeco(object):
            def __init__(self,f):
                print "In init"
                self.f = f 

            def __call__(self,args):
                print args
                print "===="
                self.f(args)


    class Test(object):
        @mydeco
        def myfunc(self,data):
            print "===="
            print "args is {0}".format(data)

    t=Test()
    t.myfunc("test123")


    `TypeError: myfunc() takes exactly 2 arguments (1 given)`
    In init
    test123
    ====
Neo
  • 133
  • 1
  • 11
  • Your decorator isn't designed to decorate methods - it swallows the implicit `self` argument. (Or, to be technically correct, it prevents the implicit `self` argument from being implicit.) – Aran-Fey Apr 12 '18 at 10:37
  • 2
    Possible duplicate of [Using classes as method decorators](https://stackoverflow.com/questions/42670667/using-classes-as-method-decorators) – Aran-Fey Apr 12 '18 at 10:37

0 Answers0