Skip to content

Commit 361dbc0

Browse files
authored
Merge pull request #10380 from bablokb/fix_deque
fix deque implementation from upstream
2 parents 4061983 + cb1fcf3 commit 361dbc0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

py/objdeque.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static mp_obj_t deque_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
208208

209209
size_t offset = mp_get_index(self->base.type, deque_len(self), index, false);
210210
size_t index_val = self->i_get + offset;
211-
if (index_val > self->alloc) {
211+
if (index_val >= self->alloc) {
212212
index_val -= self->alloc;
213213
}
214214

tests/basics/deque2.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
d[3] = 5
3232
print(d[3])
3333

34+
# Access the last element via index, when the last element is at various locations
35+
d = deque((), 2)
36+
for i in range(4):
37+
d.append(i)
38+
print(i, d[-1])
39+
40+
# Write the last element then access all elements from the end
41+
d[-1] = 4
42+
print(d[-2], d[-1])
43+
3444
# Accessing indices out of bounds raises IndexError
3545
try:
3646
d[4]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy