representation of unbound methods - strange behaviour

Fred L. Drake, Jr. fdrake at
Wed Aug 18 13:28:53 EDT 1999

Stefan Franke writes:
 > Why does this happen:
 > <unbound method A.f>
 >                 ^^^

  The "f" part of the name is taken from the function object, not the
name used to access it:

     >>> class B: pass
     >>> def h(): pass
     >>> B.f = B.g = h
     >>> B.f
     <unbound method B.h>
     >>> B.g
     <unbound method B.h>

  Whether this should be this way is open to debate, but the cost of
doing it differently probably involves doing more work in creating the 
unbound method object, which usually gets thrown away quickly.  Since
you don't normally want the repr of it at all, it's probably not worth 
changing, since that would likely slow down all method invocations.


Fred L. Drake, Jr.	     <fdrake at>
Corporation for National Research Initiatives

More information about the Python-list mailing list