Ian Bicking: the old part of his blog

Re: More on Multimethods

Just an FYI, but if the user imports div "as" another name, this code won't catch that and return self. The technique I use in PyProtocols is to check whether the decorated function's __name__ in the caller's f_locals is self. So you could do something like:

if sys._getframe(1).f_locals.get(func.__name__) is self:
    return self
    return func

Then it doesn't depend on the original generic function's definition being only accessible via its original name, in order to prevent such confusion.

Comment on More on Multimethods
by Phillip J. Eby