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
7dacda29
Commit
7dacda29
authored
Apr 08, 2004
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide more information representations of repeat() and count().
parent
94ffbb71
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
2 deletions
+27
-2
Modules/itertoolsmodule.c
Modules/itertoolsmodule.c
+27
-2
No files found.
Modules/itertoolsmodule.c
View file @
7dacda29
...
...
@@ -2051,6 +2051,12 @@ count_next(countobject *lz)
return
PyInt_FromLong
(
lz
->
cnt
++
);
}
static
PyObject
*
count_repr
(
countobject
*
lz
)
{
return
PyString_FromFormat
(
"count(%d)"
,
lz
->
cnt
);
}
PyDoc_STRVAR
(
count_doc
,
"count([firstval]) --> count object
\n
\
\n
\
...
...
@@ -2069,7 +2075,7 @@ static PyTypeObject count_type = {
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_compare */
0
,
/* tp_repr */
(
reprfunc
)
count_repr
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
...
...
@@ -2355,6 +2361,25 @@ repeat_next(repeatobject *ro)
return
ro
->
element
;
}
static
PyObject
*
repeat_repr
(
repeatobject
*
ro
)
{
PyObject
*
result
,
*
objrepr
;
objrepr
=
PyObject_Repr
(
ro
->
element
);
if
(
objrepr
==
NULL
)
return
NULL
;
if
(
ro
->
cnt
==
-
1
)
result
=
PyString_FromFormat
(
"repeat(%s)"
,
PyString_AS_STRING
(
objrepr
));
else
result
=
PyString_FromFormat
(
"repeat(%s, %d)"
,
PyString_AS_STRING
(
objrepr
),
ro
->
cnt
);
Py_DECREF
(
objrepr
);
return
result
;
}
static
int
repeat_len
(
repeatobject
*
ro
)
{
...
...
@@ -2385,7 +2410,7 @@ static PyTypeObject repeat_type = {
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_compare */
0
,
/* tp_repr */
(
reprfunc
)
repeat_repr
,
/* tp_repr */
0
,
/* tp_as_number */
&
repeat_as_sequence
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
...
...
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