Skip Montanaro wrote:
>> Another round, this time with a metaclass. As you have found partial()
>> does not work as a method because it's not a descriptor (i. e. no
>> __get__() method). Instead you can try a closure:
>>
>> def make_method(a):
>> underlying = getattr(SomeOtherClass, a)
>>
> Another round, this time with a metaclass. As you have found partial() does
> not work as a method because it's not a descriptor (i. e. no __get__()
> method). Instead you can try a closure:
>
> def make_method(a):
> underlying = getattr(SomeOtherClass, a)
> @functools.wraps(underlying)
>
Skip Montanaro wrote:
> On Thu, Apr 20, 2017 at 3:19 PM, Peter Otten <__pete...@web.de> wrote:
>
>> If being helpful really is the only purpose of the metaclass you can
>> implement a SomeClass.__dir__() method instead:
>>
>> def __dir__(self):
>> names = dir(self._instance)
>>
2017-04-20 15:55 GMT-05:00 Lele Gaifax :
> Does
>
> underlying = getattr(SomeOtherClass, a)
> def _meth(self, *args, _underlying=underlying):
> return _underlying(self._instance, *args)
>
> help?
>
Hi, Lele. Long time no chat...
I thought of that, but with _underlying declared af
On Thu, Apr 20, 2017 at 3:19 PM, Peter Otten <__pete...@web.de> wrote:
> If being helpful really is the only purpose of the metaclass you can
> implement a SomeClass.__dir__() method instead:
>
> def __dir__(self):
> names = dir(self._instance)
> #
> return names
>
Skip Montanaro writes:
> underlying = getattr(SomeOtherClass, a)
> def _meth(self, *args):
> return underlying(self._instance, *args)
Does
underlying = getattr(SomeOtherClass, a)
def _meth(self, *args, _underlying=underlying):
return _unde
Skip Montanaro wrote:
> For various reasons, I have a class which delegates much functionality to
> a singleton instance of another class (exposed by pybind11) instead of
> inheriting from that class. So, the construction looks like this (this is
> in Python 2.7):
>
> from someothermodule import
For various reasons, I have a class which delegates much functionality to a
singleton instance of another class (exposed by pybind11) instead of
inheriting from that class. So, the construction looks like this (this is
in Python 2.7):
from someothermodule import SomeOtherClass as _SomeOtherClass