Re: Metaclass conundrum - binding value from an outer scope

2017-04-22 Thread Peter Otten
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) >>

Re: Metaclass conundrum - binding value from an outer scope

2017-04-22 Thread Skip Montanaro
> 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)

Re: Metaclass conundrum - binding value from an outer scope

2017-04-21 Thread Peter Otten
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) >>

Re: Metaclass conundrum - binding value from an outer scope

2017-04-21 Thread Skip Montanaro
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

Re: Metaclass conundrum - binding value from an outer scope

2017-04-21 Thread Skip Montanaro
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

Re: Metaclass conundrum - binding value from an outer scope

2017-04-20 Thread Lele Gaifax
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,

Re: Metaclass conundrum - binding value from an outer scope

2017-04-20 Thread Peter Otten
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

Metaclass conundrum - binding value from an outer scope

2017-04-20 Thread Skip Montanaro
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