Похожие чаты

I'M applying a decorator on a method inside of a

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

14 ответов

29 просмотров
artemetra 🇺🇦-[less active] Автор вопроса

i can use func.__qualname__ to find the name of the class, but i'm looking for getting an actual reference to that class

artemetra 🇺🇦 [less active]
i can use func.__qualname__ to find the name of th...

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)

artemetra 🇺🇦-[less active] Автор вопроса
artemetra 🇺🇦 [less active]
here you go: self.__class__ 😁

I tried to make it as a code block. But it didn't work

artemetra 🇺🇦-[less active] Автор вопроса
shahar
You can either set it as a classmethod. Or (if yo...

do i set it as classmethod before or after my decorator? @classmethod @my_decorator def some_func(...) vs @my_decorator @classmethod def some_func(...)

artemetra 🇺🇦-[less active] Автор вопроса
shahar
second one

yeah, thanks :D i'll try out both the classmethod and the __class__

shahar
second one

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

artemetra 🇺🇦-[less active] Автор вопроса
Link 🪈
You can apply decorators to classes too. But why d...

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

Link 🪈
You can apply decorators to classes too. But why d...

does decorating a whole class means decorating the constructor

Fan / Ac
does decorating a whole class means decorating the...

You could even create a subclass of the decorated class inside the decorator and return it.

Похожие вопросы

Обсуждают сегодня

30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
Also, why can’t the community have a vote/ say when it comes to initiatives like buybacks. Isn’t the point of crypto decentralisation? Don’t we deserve input as long term supp...
👨🏽‍🦰
13
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
16
any reference of this implementation?
BitBuddha
29
Hi guys, any problem with Pulsebrige? Trying to transfer from wETH to ETH. First it tells me to connect my metamask "through mobile app" not desktop. Then I did and confirmed ...
Snowflakecrypto
13
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
Карта сайта