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
7505607a
Commit
7505607a
authored
Jun 10, 2008
by
Alexandre Vassalotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 2582: Fix pickling of range objects.
parent
1c9a2d96
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
0 deletions
+19
-0
Lib/test/test_range.py
Lib/test/test_range.py
+10
-0
Objects/rangeobject.c
Objects/rangeobject.c
+9
-0
No files found.
Lib/test/test_range.py
View file @
7505607a
...
...
@@ -2,6 +2,7 @@
import
test.support
,
unittest
import
sys
import
pickle
import
warnings
warnings
.
filterwarnings
(
"ignore"
,
"integer argument expected"
,
...
...
@@ -61,6 +62,15 @@ class RangeTest(unittest.TestCase):
self
.
assertEqual
(
repr
(
range
(
1
,
2
)),
'range(1, 2)'
)
self
.
assertEqual
(
repr
(
range
(
1
,
2
,
3
)),
'range(1, 2, 3)'
)
def
test_pickling
(
self
):
testcases
=
[(
13
,),
(
0
,
11
),
(
-
22
,
10
),
(
20
,
3
,
-
1
),
(
13
,
21
,
3
),
(
-
2
,
2
,
2
)]
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
):
for
t
in
testcases
:
r
=
range
(
*
t
)
self
.
assertEquals
(
list
(
pickle
.
loads
(
pickle
.
dumps
(
r
,
proto
))),
list
(
r
))
def
test_main
():
test
.
support
.
run_unittest
(
RangeTest
)
...
...
Objects/rangeobject.c
View file @
7505607a
...
...
@@ -252,6 +252,14 @@ range_repr(rangeobject *r)
r
->
start
,
r
->
stop
,
r
->
step
);
}
/* Pickling support */
static
PyObject
*
range_reduce
(
rangeobject
*
r
,
PyObject
*
args
)
{
return
Py_BuildValue
(
"(O(OOO))"
,
Py_TYPE
(
r
),
r
->
start
,
r
->
stop
,
r
->
step
);
}
static
PySequenceMethods
range_as_sequence
=
{
(
lenfunc
)
range_length
,
/* sq_length */
0
,
/* sq_concat */
...
...
@@ -269,6 +277,7 @@ PyDoc_STRVAR(reverse_doc,
static
PyMethodDef
range_methods
[]
=
{
{
"__reversed__"
,
(
PyCFunction
)
range_reverse
,
METH_NOARGS
,
reverse_doc
},
{
"__reduce__"
,
(
PyCFunction
)
range_reduce
,
METH_VARARGS
},
{
NULL
,
NULL
}
/* sentinel */
};
...
...
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