diff options
author | Armin Rigo <arigo@tunes.org> | 2006-06-08 10:56:24 (GMT) |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2006-06-08 10:56:24 (GMT) |
commit | fd01d7933bc3e9fd64d81961fbb7eabddcc82bc3 (patch) | |
tree | 04841c9342f5a07bd7436f8520aa2d54f0e54580 /Lib/test/test_class.py | |
parent | 996710fd44426f43d54034ebf3ee2355fca18f6a (diff) | |
download | cpython-fd01d7933bc3e9fd64d81961fbb7eabddcc82bc3.zip cpython-fd01d7933bc3e9fd64d81961fbb7eabddcc82bc3.tar.gz cpython-fd01d7933bc3e9fd64d81961fbb7eabddcc82bc3.tar.bz2 |
(arre, arigo) SF bug #1350060
Give a consistent behavior for comparison and hashing of method objects
(both user- and built-in methods). Now compares the 'self' recursively.
The hash was already asking for the hash of 'self'.
Diffstat (limited to 'Lib/test/test_class.py')
-rw-r--r-- | Lib/test/test_class.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py index 92c220e..6c91deb 100644 --- a/Lib/test/test_class.py +++ b/Lib/test/test_class.py @@ -368,3 +368,37 @@ except AttributeError, x: pass else: print "attribute error for I.__init__ got masked" + + +# Test comparison and hash of methods +class A: + def __init__(self, x): + self.x = x + def f(self): + pass + def g(self): + pass + def __eq__(self, other): + return self.x == other.x + def __hash__(self): + return self.x +class B(A): + pass + +a1 = A(1) +a2 = A(2) +assert a1.f == a1.f +assert a1.f != a2.f +assert a1.f != a1.g +assert a1.f == A(1).f +assert hash(a1.f) == hash(a1.f) +assert hash(a1.f) == hash(A(1).f) + +assert A.f != a1.f +assert A.f != A.g +assert B.f == A.f +assert hash(B.f) == hash(A.f) + +# the following triggers a SystemError in 2.4 +a = A(hash(A.f.im_func)^(-1)) +hash(a.f) |