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
a6389716
Commit
a6389716
authored
Feb 01, 2016
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge
parent
94c30898
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
18 deletions
+16
-18
Doc/library/collections.rst
Doc/library/collections.rst
+2
-2
Lib/test/test_deque.py
Lib/test/test_deque.py
+12
-11
Modules/_collectionsmodule.c
Modules/_collectionsmodule.c
+2
-5
No files found.
Doc/library/collections.rst
View file @
a6389716
...
...
@@ -477,8 +477,8 @@ or subtracting from an empty counter.
Insert *x* into the deque at position *i*.
If the insertion
causes a bounded deque to grow beyond *maxlen*, the
rightmost element is then removed to restore the size limit
.
If the insertion
would cause a bounded deque to grow beyond *maxlen*,
an :exc:`IndexError` is raised
.
.. versionadded:: 3.5
...
...
Lib/test/test_deque.py
View file @
a6389716
...
...
@@ -304,19 +304,20 @@ class TestBasic(unittest.TestCase):
s
.
insert
(
i
,
'Z'
)
self
.
assertEqual
(
list
(
d
),
s
)
def
test_in
dex
_bug_26194
(
self
):
def
test_in
sert
_bug_26194
(
self
):
data
=
'ABC'
for
i
in
range
(
len
(
data
)
+
1
):
d
=
deque
(
data
,
len
(
data
))
d
.
insert
(
i
,
None
)
s
=
list
(
data
)
s
.
insert
(
i
,
None
)
s
.
pop
()
self
.
assertEqual
(
list
(
d
),
s
)
if
i
<
len
(
data
):
self
.
assertIsNone
(
d
[
i
])
d
=
deque
(
data
,
maxlen
=
len
(
data
))
with
self
.
assertRaises
(
IndexError
):
d
.
insert
(
2
,
None
)
elements
=
'ABCDEFGHI'
for
i
in
range
(
-
len
(
elements
),
len
(
elements
)):
d
=
deque
(
elements
,
maxlen
=
len
(
elements
)
+
1
)
d
.
insert
(
i
,
'Z'
)
if
i
>=
0
:
self
.
assertEqual
(
d
[
i
],
'Z'
)
else
:
self
.
assert
True
(
None
not
in
d
)
self
.
assert
Equal
(
d
[
i
-
1
],
'Z'
)
def
test_imul
(
self
):
for
n
in
(
-
10
,
-
1
,
0
,
1
,
2
,
10
,
1000
):
...
...
Modules/_collectionsmodule.c
View file @
a6389716
...
...
@@ -1085,16 +1085,13 @@ deque_insert(dequeobject *deque, PyObject *args)
Py_ssize_t
index
;
Py_ssize_t
n
=
Py_SIZE
(
deque
);
PyObject
*
value
;
PyObject
*
oldvalue
;
PyObject
*
rv
;
if
(
!
PyArg_ParseTuple
(
args
,
"nO:insert"
,
&
index
,
&
value
))
return
NULL
;
if
(
deque
->
maxlen
==
Py_SIZE
(
deque
))
{
if
(
index
>=
deque
->
maxlen
||
Py_SIZE
(
deque
)
==
0
)
Py_RETURN_NONE
;
oldvalue
=
deque_pop
(
deque
,
NULL
);
Py_DECREF
(
oldvalue
);
PyErr_SetString
(
PyExc_IndexError
,
"deque already at its maximum size"
);
return
NULL
;
}
if
(
index
>=
n
)
return
deque_append
(
deque
,
value
);
...
...
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