Nick Coghlan added the comment:
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)
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue4331>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com