>
> So it looks like we're stuck.  Any ideas?
>
>
This works for both Python2 and Python3:

from functools import wraps

isPython3 = True

def cmd(command_name):

    def inner_cmd(func):
        @wraps(func)
        def _decorator(*args, **kwargs):
            type0 = args and str(type(args[0])) or ""
            if isPython3 and '.' in type0:
                className = args[0].__class__.__name__
            elif not isPython3 and type0 == "<type 'instance'>":
                className = args[0].__class__.__name__
            else:
                className = None

            print('** func:', func.__name__, 'class:', className)
            return func(*args, **kwargs)
        return _decorator
    return inner_cmd


@cmd('command1')
def pureFunction(event=None):

    print('-- pureFunction:', event)
    return ("...exit pureFunction")

class MyClass:

    @cmd('command2')
    def aMethod(self, event=None):
        print('-- self',self,'event',event)


def tests():
    pureFunction()
    pureFunction("abc")
    pureFunction(pureFunction)
    pureFunction(MyClass)
    MyClass().aMethod()
    MyClass().aMethod("abc")
    MyClass().aMethod(pureFunction)
    MyClass().aMethod(MyClass)

tests()


 Reinhard

-- 
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