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
7989a4dc
Commit
7989a4dc
authored
Dec 03, 2008
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport r67478
parent
fd8a1ec4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
8 deletions
+14
-8
Lib/test/list_tests.py
Lib/test/list_tests.py
+2
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/listobject.c
Objects/listobject.c
+9
-8
No files found.
Lib/test/list_tests.py
View file @
7989a4dc
...
...
@@ -84,6 +84,8 @@ class CommonTest(seq_tests.CommonTest):
self
.
assertRaises
(
StopIteration
,
r
.
next
)
self
.
assertEqual
(
list
(
reversed
(
self
.
type2test
())),
self
.
type2test
())
# Bug 3689: make sure list-reversed-iterator doesn't have __len__
self
.
assertRaises
(
TypeError
,
len
,
reversed
([
1
,
2
,
3
]))
def
test_setitem
(
self
):
a
=
self
.
type2test
([
0
,
1
])
...
...
Misc/NEWS
View file @
7989a4dc
...
...
@@ -16,6 +16,9 @@ Core and Builtins
interpreter to abort ("Fatal Python error: Could not reset the stack!")
instead of throwing a MemoryError.
- Issue #3689: The list reversed iterator now supports __length_hint__
instead of __len__. Behavior now matches other reversed iterators.
- Issue #4367: Python would segfault during compiling when the unicodedata
module couldn't be imported and \N escapes were present.
...
...
Objects/listobject.c
View file @
7989a4dc
...
...
@@ -2911,11 +2911,11 @@ static PyObject *list_reversed(PyListObject *, PyObject *);
static
void
listreviter_dealloc
(
listreviterobject
*
);
static
int
listreviter_traverse
(
listreviterobject
*
,
visitproc
,
void
*
);
static
PyObject
*
listreviter_next
(
listreviterobject
*
);
static
Py
_ssize_t
listreviter_len
(
listreviterobject
*
);
static
Py
Object
*
listreviter_len
(
listreviterobject
*
);
static
Py
SequenceMethods
listreviter_as_sequence
=
{
(
lenfunc
)
listreviter_len
,
/* sq_length */
0
,
/* sq_concat
*/
static
Py
MethodDef
listreviter_methods
[]
=
{
{
"__length_hint__"
,
(
PyCFunction
)
listreviter_len
,
METH_NOARGS
,
length_hint_doc
},
{
NULL
,
NULL
}
/* sentinel
*/
};
PyTypeObject
PyListRevIter_Type
=
{
...
...
@@ -2931,7 +2931,7 @@ PyTypeObject PyListRevIter_Type = {
0
,
/* tp_compare */
0
,
/* tp_repr */
0
,
/* tp_as_number */
&
listreviter_as_sequence
,
/* tp_as_sequence */
0
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
0
,
/* tp_hash */
0
,
/* tp_call */
...
...
@@ -2947,6 +2947,7 @@ PyTypeObject PyListRevIter_Type = {
0
,
/* tp_weaklistoffset */
PyObject_SelfIter
,
/* tp_iter */
(
iternextfunc
)
listreviter_next
,
/* tp_iternext */
listreviter_methods
,
/* tp_methods */
0
,
};
...
...
@@ -3002,11 +3003,11 @@ listreviter_next(listreviterobject *it)
return
NULL
;
}
static
Py
_ssize_t
static
Py
Object
*
listreviter_len
(
listreviterobject
*
it
)
{
Py_ssize_t
len
=
it
->
it_index
+
1
;
if
(
it
->
it_seq
==
NULL
||
PyList_GET_SIZE
(
it
->
it_seq
)
<
len
)
return
0
;
return
len
;
len
=
0
;
return
PyLong_FromSsize_t
(
len
)
;
}
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