On Wednesday, May 13, 2015 at 5:13:46 AM UTC-5, 
reinhard.engel...@googlemail.com wrote:

> It's even easier...

There is no obvious way to recover the class name in Python 2. Here is my 
test code:

def cmd(command_name):
    
    def _decorator(func):
        base = func.__code__ if g.isPython3 else func.func_code
        isMethod = 'self' in base.co_varnames
        g.trace('method: %5s %s' % (isMethod,func))
    return _decorator

@cmd('command1')
def pureFunction(event=None):
    g.trace(event)
    return ("...exit pureFunction")

class MyClass:

    @cmd('command2')
    def aMethod(self, event=None):
        g.trace('self',self,'event',event)

With Python 3 this produces

_decorator method: False <function pureFunction at 0x08A11A08>
_decorator method:  True <function MyClass.aMethod at 0x08A11A50>

With Python 2 it produces:

_decorator method: False <function pureFunction at 0x094C05F0>
_decorator method:  True <function aMethod at 0x094C06F0>

You would think there recovering the class name would be easy.  But no.  
func.im_class does not exist because func is not a bound method. 
__qualname__ exists only in Python 3. A close examination of dir(func) 
shows no other obvious way to get the class name.

So it looks like we're stuck.  Any ideas?

Edward

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to