This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Alexander.Belopolsky, Christophe Simonis, alonho, anacrolix, belopolsky, eckhardt, ironfroggy, jackdied, jcea, ncoghlan, r.david.murray, rhettinger, ssadler
Date 2013-10-26.17:18:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1382807918.91.0.309189890838.issue4331@psf.upfronthosting.co.za>
In-reply-to
Content
I like your suggestion of not providing __call__(), as I don't see a way to make it work with arbitrary underlying descriptors, and neither classmethod nor staticmethod is callable.

In terms of usage, I think this approach will be OK, as in practice I expect @classmethod, etc, will be applied to the initial method definition as appropriate, so they won't need to be inline except in test cases like these.

Additional test cases needed:

    A().add10class(5)
    A().add10static(5)
    A.add10(A(), 5)

All three should produce 15 as the result, and print the same thing as the following:

    A.add10class(5)
    A.add10static(5)
    A().add10(5)

A test method that uses a partial instance as the callable would also be helpful in assuring the edge cases are covered.

I believe it may be necessary to have a __get__ method something like:

    def _make_unbound_method(self, cls):
        def _unbound_method(*args, **kwds):
            call_keywords = self.keywords.copy()
            call_keywords.update(keywords)
            return self.func(*(self.args + args), **call_keywords)
        _unbound_method.__objclass__ = cls
        return _unbound_method


    def __get__(self, obj, cls):
        get = getattr(self.func, "__get__")
        if get is None:
            if obj is None:
                return self._make_unbound_method(cls)
            callable = self.func
        else:
            callable = get(obj, cls)
            if callable is self.func:
                return self._make_unbound_method(cls)
        return partial(callable, *self.args, **self.keywords)
History
Date User Action Args
2013-10-26 17:18:38ncoghlansetrecipients: + ncoghlan, rhettinger, jcea, belopolsky, ironfroggy, jackdied, Christophe Simonis, ssadler, eckhardt, r.david.murray, Alexander.Belopolsky, anacrolix, alonho
2013-10-26 17:18:38ncoghlansetmessageid: <1382807918.91.0.309189890838.issue4331@psf.upfronthosting.co.za>
2013-10-26 17:18:38ncoghlanlinkissue4331 messages
2013-10-26 17:18:38ncoghlancreate