GrahamDumpleton / wrapt

A Python module for decorators, wrappers and monkey patching.
BSD 2-Clause "Simplified" License
2.04k stars 230 forks source link

Doc: universal decos, would `inspect.ismethod` be better? #149

Closed dimaqq closed 4 years ago

dimaqq commented 4 years ago

inspect.ismethod(object) Return True if the object is a bound method written in Python.

Would this be cleaner test than instance is not None and not isclass(wrapped)?

Or am I missing a corner case?

GrahamDumpleton commented 4 years ago

The implementation of inspect.ismethod() is:

def ismethod(object):
    """Return true if the object is an instance method.

    Instance method objects provide these attributes:
        __doc__         documentation string
        __name__        name with which this method was defined
        __func__        function object containing implementation of method
        __self__        instance to which this method is bound"""
    return isinstance(object, types.MethodType)

The wrapped callable need not be an instance of types.MethodType. For example, in the case of nested decorators.

dimaqq commented 4 years ago

Make perfect sense!