class, how do i get that class inside of the decorator? i tried calling dir() on the method but i didn't find anything useful
i can use func.__qualname__ to find the name of the class, but i'm looking for getting an actual reference to that class
You can either set it as a classmethod. Or (if you really want to), you can access it with: self.\_\_class\_\_ (without the backslashes, Cant find a way to display it correctly without them)
here you go: self.__class__ 😁
I tried to make it as a code block. But it didn't work
do i set it as classmethod before or after my decorator? @classmethod @my_decorator def some_func(...) vs @my_decorator @classmethod def some_func(...)
yeah, thanks :D i'll try out both the classmethod and the __class__
so what is the difference btw them
You can apply decorators to classes too. But why do you want to access the method's class with the decorator, idk what are you trying to do, but it looks like it can get really messy quickly if you do that
i know i can apply decorators to classes too and i'm actually using that. i'm trying out different solutions/desings as i'm currently very early in my project and unsure what's the best way to achieve what i need, thank you though
does decorating a whole class means decorating the constructor
No, it decorates the whole class
You could even create a subclass of the decorated class inside the decorator and return it.
Обсуждают сегодня