Suppose I have a simple decorator, and a classes method and a function which I both decorate with that decorator:
import functools
def decorator(func):
@functools.wraps(func)
def call(*args):
print(args)
func(*args)
return call
class cls:
@decorator
def meth(self, a):
pass
@decorator
def func(c):
pass
cls().meth("a")
func("c")
I get following output:
(<__main__.cls object at 0x7f4665c50130>, 'a')
('c',)
But I want to remove the self
argument when the decorator is used on a method, so that the output becomes:
('a',)
('c',)
But, if I simply add args.pop(0)
, I will remove the first argument even if it is not self
. How can I only remove the first argument if it is self
?
Note: I read some solutions with a long code using inspect
- but there must be a shorter, easier way in this great and simple-to-use programming language ?
EDIT: Using @staticmethod
is not an option for me, because I need the self
parameter in the method itself. I only don't want it to get printed.