[Python] How to check if an object is a method_descriptor

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    Given an object, how can I make a check if it is a method_descriptor?

    is_method_descriptor = isinstance(obj, method_descriptor) # does not work


    The problem: method_descriptor is a builtin but not an accessible variable. I neither found it in builtins or types.


    I use Python 3.10 here if relevant.

    I am looking for a proof of concept out of curiosity how to get hold of the class for an isinstance check if I actually wanted to, or alternative checks that satisfy it.
    For my Sphinx related problem where I encountered them unexpectedly I (hopefully) found a workaround already, but still need to test it if it is sufficient or if I should replace it with a more explicit check that I am here looking for.

    Continue reading...

Compartilhe esta Página