mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
(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'.
This commit is contained in:
parent
996710fd44
commit
fd01d7933b
4 changed files with 81 additions and 11 deletions
|
|
@ -4014,11 +4014,24 @@ def methodwrapper():
|
|||
|
||||
l = []
|
||||
vereq(l.__add__, l.__add__)
|
||||
verify(l.__add__ != [].__add__)
|
||||
vereq(l.__add__, [].__add__)
|
||||
verify(l.__add__ != [5].__add__)
|
||||
verify(l.__add__ != l.__mul__)
|
||||
verify(l.__add__.__name__ == '__add__')
|
||||
verify(l.__add__.__self__ is l)
|
||||
verify(l.__add__.__objclass__ is list)
|
||||
vereq(l.__add__.__doc__, list.__add__.__doc__)
|
||||
try:
|
||||
hash(l.__add__)
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
raise TestFailed("no TypeError from hash([].__add__)")
|
||||
|
||||
t = ()
|
||||
t += (7,)
|
||||
vereq(t.__add__, (7,).__add__)
|
||||
vereq(hash(t.__add__), hash((7,).__add__))
|
||||
|
||||
def notimplemented():
|
||||
# all binary methods should be able to return a NotImplemented
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue