Message201377
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) |
|
Date |
User |
Action |
Args |
2013-10-26 17:18:38 | ncoghlan | set | recipients:
+ ncoghlan, rhettinger, jcea, belopolsky, ironfroggy, jackdied, Christophe Simonis, ssadler, eckhardt, r.david.murray, Alexander.Belopolsky, anacrolix, alonho |
2013-10-26 17:18:38 | ncoghlan | set | messageid: <1382807918.91.0.309189890838.issue4331@psf.upfronthosting.co.za> |
2013-10-26 17:18:38 | ncoghlan | link | issue4331 messages |
2013-10-26 17:18:38 | ncoghlan | create | |
|