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
fd3f8e1e
Commit
fd3f8e1e
authored
Aug 09, 2006
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
__hash__ may now return long int; the final hash
value is obtained by invoking hash on the long int. Fixes #1536021.
parent
703bb1dd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
6 deletions
+24
-6
Doc/ref/ref3.tex
Doc/ref/ref3.tex
+5
-0
Lib/test/test_builtin.py
Lib/test/test_builtin.py
+9
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/classobject.c
Objects/classobject.c
+3
-5
Objects/typeobject.c
Objects/typeobject.c
+4
-1
No files found.
Doc/ref/ref3.tex
View file @
fd3f8e1e
...
...
@@ -1307,6 +1307,11 @@ defines mutable objects and implements a \method{__cmp__()} or
since the dictionary implementation requires that a key's hash value
is immutable (if the object's hash value changes, it will be in the
wrong hash bucket).
\versionchanged
[
\method
{__
hash
__
()
}
may now also return a long
integer object; the 32-bit integer is then derived from the hash
of that object]
{
2.5
}
\withsubitem
{
(object method)
}{
\ttindex
{__
cmp
__
()
}}
\end{methoddesc}
...
...
Lib/test/test_builtin.py
View file @
fd3f8e1e
...
...
@@ -640,6 +640,15 @@ class BuiltinTest(unittest.TestCase):
def
f
():
pass
self
.
assertRaises
(
TypeError
,
hash
,
[])
self
.
assertRaises
(
TypeError
,
hash
,
{})
# Bug 1536021: Allow hash to return long objects
class
X
:
def
__hash__
(
self
):
return
2
**
100
self
.
assertEquals
(
type
(
hash
(
X
())),
int
)
class
Y
(
object
):
def
__hash__
(
self
):
return
2
**
100
self
.
assertEquals
(
type
(
hash
(
Y
())),
int
)
def
test_hex
(
self
):
self
.
assertEqual
(
hex
(
16
),
'0x10'
)
...
...
Misc/NEWS
View file @
fd3f8e1e
...
...
@@ -12,6 +12,9 @@ What's New in Python 2.5 release candidate 1?
Core and builtins
-----------------
- Bug #1536021: __hash__ may now return long int; the final hash
value is obtained by invoking hash on the long int.
- Bug #1536786: buffer comparison could emit a RuntimeWarning.
- Bug #1535165: fixed a segfault in input() and raw_input() when
...
...
Objects/classobject.c
View file @
fd3f8e1e
...
...
@@ -934,11 +934,9 @@ instance_hash(PyInstanceObject *inst)
Py_DECREF
(
func
);
if
(
res
==
NULL
)
return
-
1
;
if
(
PyInt_Check
(
res
))
{
outcome
=
PyInt_AsLong
(
res
);
if
(
outcome
==
-
1
)
outcome
=
-
2
;
}
if
(
PyInt_Check
(
res
)
||
PyLong_Check
(
res
))
/* This already converts a -1 result to -2. */
outcome
=
res
->
ob_type
->
tp_hash
(
res
);
else
{
PyErr_SetString
(
PyExc_TypeError
,
"__hash__() should return an int"
);
...
...
Objects/typeobject.c
View file @
fd3f8e1e
...
...
@@ -4559,7 +4559,10 @@ slot_tp_hash(PyObject *self)
Py_DECREF
(
func
);
if
(
res
==
NULL
)
return
-
1
;
h
=
PyInt_AsLong
(
res
);
if
(
PyLong_Check
(
res
))
h
=
res
->
ob_type
->
tp_hash
(
res
);
else
h
=
PyInt_AsLong
(
res
);
Py_DECREF
(
res
);
}
else
{
...
...
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