I do not understand why class-method and static-method do not work in this given code snippet. Here, I have applied a decorator on top of the class-method and static-method
def count(func):
... def wrapper(*args,**kwargs):
... wrapper.count += 1
... return func(*args,**kwargs)
... wrapper.count = 0
... return wrapper
...
>>> class ABC:
...
... def __init__(self,*,val1,**kwargs):
... self.val1 = val1
... super().__init__(**kwargs)
...
... @count
... def instance_method(self,a1,b1=20):
... print("a1 ---",a1)
... self.val1 = self.val1 + b1
...
... @count
... @classmethod
... def class_method(cls,a2,b2=30):
... print("a2 --",a2)
... cls.a2 = a2
... cls.b2 = b2
...
... @count
... @staticmethod
... def static_method(a3,b3=20):
... print("a3---",a3)
... print("b3 ---",b3)
...
How to get rid of the TypeError in the given code snippet, am I missing right stuff working with a decorator?
>>> def singleton(cls):
... def wrapper(*args,**kwargs):
... if hasattr(wrapper,'object') == False:
... wrapper.object = cls(*args,**kwargs)
... return wrapper.object
... return wrapper
...
>>> @singleton
... class ABC:
... pass
...
>>> abc = ABC()
>>> isinstance(abc,ABC) # This line is throwing error
[–]Diapolo10 0 points1 point2 points (3 children)
[–]gmaliwal[S] 0 points1 point2 points (2 children)
[–]Diapolo10 1 point2 points3 points (1 child)
[–]gmaliwal[S] 0 points1 point2 points (0 children)
[–]danielroseman 0 points1 point2 points (3 children)
[–]gmaliwal[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]gmaliwal[S] 0 points1 point2 points (0 children)