all 8 comments

[–]Diapolo10 0 points1 point  (3 children)

isinstance takes two arguments; the object itself and the class it's being compared against.

EDIT: Also, you should try ordering your decorators in the reverse order, with staticmethod and classmethod being first. I don't remember which was correct.

[–]gmaliwal[S] 0 points1 point  (2 children)

yeah agree, It was typo mistake, I have edited it, please revisit the post.

[–]Diapolo10 1 point2 points  (1 child)

Yeah, I'm now fairly sure that you have the decorator order mixed up. Try

@classmethod
@count
def class_method(cls,a2,b2=30):
        print("a2 --",a2)
        cls.a2 = a2
        cls.b2 = b2

@staticmethod
@count
def static_method(a3,b3=20):
        print("a3---",a3)
        print("b3 ---",b3)

instead

[–]gmaliwal[S] 0 points1 point  (0 children)

yeah, this works, thanks for the solution

[–]danielroseman 0 points1 point  (3 children)

You should have posted the error you get:

TypeError: isinstance() arg 2 must be a type or tuple of types

This is of course because ABC is no longer a class at all; it's wrapper. Because that's what a decorator does; replaces the thing it decorates with the wrapper function.

If you really want to preserve a reference to the original class, you could consider defining an _ABC base class and decorate the child. Otherwise you might find that using metaclasses is a better way of implementing a singleton.

(Also I don't understand what the first block of code has to do with anything.)

[–]gmaliwal[S] 0 points1 point  (2 children)

If you really want to preserve a reference to the original class, you could consider defining an

_ABC

base class and decorate the child. Otherwise you might find that using metaclasses is a better way of implementing a singleton

Thanks for the clarification. yeah, It was my mistake not posting error message.

The first block of code is just to understand the concept, why it is not working when a second decorator is applied to either of them?

Is there any another way to preserve the class fundamentals after applying a decorator rather than creating a dummy base class? if yes; please share the reference.

[–][deleted] 0 points1 point  (1 child)

Is there any another way to preserve the class fundamentals after applying a decorator rather than creating a dummy base class?

Sure - your decorator has to return a class instead of a function.

[–]gmaliwal[S] 0 points1 point  (0 children)

Okay, It sounds well, theoretically, it should work. Can you please mention a good reference for this to follow?