| On Mon, 11 May 2015 05:16:24 -0700 (PDT)
| "Edward K. Ream" <[email protected]> wrote:
::
> On Sunday, May 10, 2015 at 7:03:02 AM UTC-5, Edward K. Ream wrote:
>
> The primary task is to associate a decorator with an *instance *of a
> class.
> > The code that I pushed yesterday does this by defining a cmd
> > decorator for each class that defines a Leo command.
> >
> > When I awoke this morning I saw that a single dict, say
> > *g.cmd_instance_dict*, could eliminate the need for per-class
> > decorators.
>
> Alas, there appears to be no way for the wrapper to recover the class
> name. Indeed, the "func" argument to the wrapper is a *function*,
> not a method. For example, func.__class__ is None.
>
> Following Reinhard's suggestions, it might be possible to use the
> inspect module or the func's code object to recover the enclosing
> class's name. But I wouldn't bet on it.
>
> So it appears that per-class cmd decorators will be required. It's
> not the end of the world :-)
Right, that's a week from Wednesday :-) But are you suggesting
different names for different decorators? That seems cumbersome.
Have to admit I've lost track of which problem you're trying to solve,
but:
.. code:: py
def dec(f):
def x(*args, **kwargs):
print args[0]
f(*args, **kwargs)
return x
class test:
@dec
def atest(self, etc):
print "etc."
t = test()
t.atest(3)
can get the class from args[0] - but I haven't been following closely
enough to know if that's relevant.
Cheers -Terry
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.