Author maggyero
Recipients docs@python, eric.araujo, ezio.melotti, maggyero, mdk, rhettinger, willingc
Date 2019-06-09.07:09:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1560064171.96.0.794533988618.issue37203@roundup.psfhosted.org>
In-reply-to
Content
@Raymond Hettinger

> The goal in the descriptor how-to is to give an understanding of how descriptors work.

Okay. So I don't know if that was clear in my last message but that also means replacing the current "Function" implementation:

class Function(object):
    . . .
    def __get__(self, obj, objtype=None):
        "Simulate func_descr_get() in Objects/funcobject.c"
        if obj is None:
            return self
        return types.MethodType(self, obj)

with something like this:

class Function(object):
    . . .
    def __get__(self, obj, objtype=None):
        "Simulate func_descr_get() in Objects/funcobject.c"
        if obj is None:
            return self
        def newfunc(*args, **kwargs):
            return self(obj, *args, **kwargs)
        return newfunc
        # "newfunc" emulates "types.MethodType(self, obj)"

And as you said, adding a similar comment to the "ClassMethod" implementation (and **kwargs):

class ClassMethod(object):
    "Emulate PyClassMethod_Type() in Objects/funcobject.c"

    def __init__(self, f):
        self.f = f

    def __get__(self, obj, klass=None):
        if klass is None:
            klass = type(obj)
        def newfunc(*args, **kwargs):
            return self.f(klass, *args, **kwargs)
        return newfunc
        # "newfunc" emulates "types.MethodType(self.f, klass)"
History
Date User Action Args
2019-06-09 07:09:31maggyerosetrecipients: + maggyero, rhettinger, ezio.melotti, eric.araujo, docs@python, willingc, mdk
2019-06-09 07:09:31maggyerosetmessageid: <1560064171.96.0.794533988618.issue37203@roundup.psfhosted.org>
2019-06-09 07:09:31maggyerolinkissue37203 messages
2019-06-09 07:09:31maggyerocreate