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
03b43d8a
Commit
03b43d8a
authored
May 21, 2007
by
Walter Dörwald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repr(range(10)) now returns 'range(0, 10)' for clarity.
parent
c2f6a58f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
11 deletions
+4
-11
Lib/test/test_xrange.py
Lib/test/test_xrange.py
+1
-1
Objects/rangeobject.c
Objects/rangeobject.c
+3
-10
No files found.
Lib/test/test_xrange.py
View file @
03b43d8a
...
...
@@ -57,7 +57,7 @@ class XrangeTest(unittest.TestCase):
self
.
assertEqual
(
len
(
r
),
sys
.
maxint
)
def
test_repr
(
self
):
self
.
assertEqual
(
repr
(
range
(
1
)),
'range(1)'
)
self
.
assertEqual
(
repr
(
range
(
1
)),
'range(
0,
1)'
)
self
.
assertEqual
(
repr
(
range
(
1
,
2
)),
'range(1, 2)'
)
self
.
assertEqual
(
repr
(
range
(
1
,
2
,
3
)),
'range(1, 2, 3)'
)
...
...
Objects/rangeobject.c
View file @
03b43d8a
...
...
@@ -234,24 +234,17 @@ range_item(rangeobject *r, Py_ssize_t i)
static
PyObject
*
range_repr
(
rangeobject
*
r
)
{
Py_ssize_t
ist
art
,
ist
ep
;
Py_ssize_t
istep
;
/* Check for special case values for printing. We don't always
need the st
art or step values
. We don't care about errors
need the st
ep value
. We don't care about errors
(it means overflow), so clear the errors. */
istart
=
PyNumber_AsSsize_t
(
r
->
start
,
NULL
);
if
(
istart
!=
0
||
(
istart
==
-
1
&&
PyErr_Occurred
()))
{
PyErr_Clear
();
}
istep
=
PyNumber_AsSsize_t
(
r
->
step
,
NULL
);
if
(
istep
!=
1
||
(
istep
==
-
1
&&
PyErr_Occurred
()))
{
PyErr_Clear
();
}
if
(
istart
==
0
&&
istep
==
1
)
return
PyUnicode_FromFormat
(
"range(%R)"
,
r
->
stop
);
else
if
(
istep
==
1
)
if
(
istep
==
1
)
return
PyUnicode_FromFormat
(
"range(%R, %R)"
,
r
->
start
,
r
->
stop
);
else
return
PyUnicode_FromFormat
(
"range(%R, %R, %R)"
,
...
...
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