[issue3500] unbound methods of different classes compare equal

Jean-Paul Calderone report at bugs.python.org
Mon Aug 4 21:13:34 CEST 2008


New submission from Jean-Paul Calderone <exarkun at divmod.com>:

If a method is inherited by two different classes, then the unbound
method objects which can be retrieved from those classes compare equal
to each other.  For example:

  Python 2.6b2+ (trunk:65502M, Aug  4 2008, 15:05:07)
  [GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> class X:
  ...     def y(self):
  ...             pass
  ...
  >>> class A(X):
  ...     pass
  ...
  >>> class B(X):
  ...     pass
  ...
  >>> A.y == B.y
  True

This is bad behavior because A.y and B.y are otherwise distinguishable
(for example, they repr differently, they have different values for the
`im_class´ attribute, they cannot be used interchangably for invoking
the method because they place different type restrictions on the `self´
parameter, etc).

----------
components: Interpreter Core
messages: 70714
nosy: exarkun
severity: normal
status: open
title: unbound methods of different classes compare equal
type: behavior
versions: Python 2.4, Python 2.5, Python 2.6

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


More information about the Python-bugs-list mailing list