Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
884f46c3
Commit
884f46c3
authored
May 03, 2011
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Plain Diff
Fix __hash__ in functools.cmp_to_key() to work with collections.Hashable.
parents
3d328677
b0361616
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
3 deletions
+6
-3
Lib/functools.py
Lib/functools.py
+1
-2
Lib/test/test_functools.py
Lib/test/test_functools.py
+3
-1
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/functools.py
View file @
884f46c3
...
...
@@ -111,8 +111,7 @@ def cmp_to_key(mycmp):
return
mycmp
(
self
.
obj
,
other
.
obj
)
>=
0
def
__ne__
(
self
,
other
):
return
mycmp
(
self
.
obj
,
other
.
obj
)
!=
0
def
__hash__
(
self
):
raise
TypeError
(
'hash not implemented'
)
__hash__
=
None
return
K
try
:
...
...
Lib/test/test_functools.py
View file @
884f46c3
import
functools
import
collections
import
sys
import
unittest
from
test
import
support
...
...
@@ -510,6 +511,7 @@ class TestCmpToKey(unittest.TestCase):
key
=
functools
.
cmp_to_key
(
mycmp
)
k
=
key
(
10
)
self
.
assertRaises
(
TypeError
,
hash
,
k
)
self
.
assertNotIsInstance
(
k
,
collections
.
Hashable
)
class
TestTotalOrdering
(
unittest
.
TestCase
):
...
...
@@ -718,12 +720,12 @@ class TestLRU(unittest.TestCase):
def
test_main
(
verbose
=
None
):
test_classes
=
(
TestCmpToKey
,
TestPartial
,
TestPartialSubclass
,
TestPythonPartial
,
TestUpdateWrapper
,
TestTotalOrdering
,
TestCmpToKey
,
TestWraps
,
TestReduce
,
TestLRU
,
...
...
Misc/NEWS
View file @
884f46c3
...
...
@@ -141,6 +141,8 @@ Library
- logging: don'
t
define
QueueListener
if
Python
has
no
thread
support
.
-
functools
.
cmp_to_key
()
now
works
with
collections
.
Hashable
().
-
Issue
#
11277
:
mmap
.
mmap
()
calls
fcntl
(
fd
,
F_FULLFSYNC
)
on
Mac
OS
X
to
get
around
a
mmap
bug
with
sparse
files
.
Patch
written
by
Steffen
Daode
Nurpmeso
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment