[Python-Dev] repr(x) != x.repr() (original) (raw)

Oren Tirosh oren-py-d@hishome.net
Thu, 28 Mar 2002 10:20:07 -0500


This phenomenon is not really specific to repr(). It occurs with new-style classes when methods are assigned.

Example:

class A(object): def repr(self): return 'abc'

a = A() a.repr = lambda: 'abc' repr(a) 'abc' a.repr() '123'

Whenever the method is accessed by Python code it sees the assigned method in the object's dict. Builtins like repr(), iter() etc, see the original class method. With classic objects both Python and C code see the assigned function. This is bug #515336 on sourceforge.

Is anyone aware of any other cases where C code and Python code don't see objects the same way?

Oren