[issue15397] Unbinding of methods

Richard Oudkerk report at bugs.python.org
Fri Jul 20 19:08:20 CEST 2012


Richard Oudkerk <shibturn at gmail.com> added the comment:

Can't you unbind without any changes to the C code by doing

    def unbind(f):
        if hasattr(f, '__func__'):
            return f.__func__
        self = getattr(f, '__self__', None)
        if self is not None and not isinstance(self, types.ModuleType):
            return getattr(type(f.__self__), f.__name__)
        raise TypeError('not a bound method')

Also, I am not convinced that it is a good idea to return f if f is already "unbound".  In practice I think you will always need to treat the bound and the unbound cases differently.

----------
nosy: +sbt

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15397>
_______________________________________


More information about the Python-bugs-list mailing list