I have written a decorator using a class. Below is the code
class to_uppercase:
def __init__(self, func):
self.func = func
def __call__(self, *args, **kwargs):
return self.func(*args, *kwargs).upper()
When I apply this decorator on a function, it works.
@to_uppercase
def format_string(string):
return string
>>> format_string('wORD wORD')
'WORD WORD'
Now when I apply the same decorator on a method, I get an error.
class base_string:
def __init__(self, base):
self.base = base
@to_uppercase
def get_base_string(self):
return self.base
s = base_string('word worD')
s.get_base_string()
TypeError: get_base_string() missing 1 required positional argument: 'self'
What am I missing here?