[Python] How to check if object attribute is of type method-wrapper?

Discussão em 'Python' iniciado por Stack, Agosto 28, 2025.

  1. Stack

    Stack Membro Participativo

    Some of the callable() attributes of an object are of type <class 'method-wrapper'>. Is it possible to check if a callable is of type method-wrapper?

    For example isinstance(object, methodwrapper) or something like that?


    Basically what I am trying to achieve is this: I have an object a of type A and I want to serialize it so I can send it over the wire. I also want to "serialize" the methods of that object. In particular, I want to send the source for each of the methods over the wire so it can be executed in some scope on the other side and injected into a re-creation of the a because the methods may have been changed or updated etc. So I go over all the methods, "serializing" them one at a time and then sending the json dictionary of attribute_name -> attribute over the wire. But I don't want to try to serialize methods of type method-wrapper. Now one way would just be to try and catch an exception when trying to serialize method-wrappers but I was wondering if there's another way.

    Continue reading...

Compartilhe esta Página