Skip to content

fix deque implementation from upstream #10380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion py/objdeque.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ static mp_obj_t deque_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {

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

Expand Down
10 changes: 10 additions & 0 deletions tests/basics/deque2.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
d[3] = 5
print(d[3])

# Access the last element via index, when the last element is at various locations
d = deque((), 2)
for i in range(4):
d.append(i)
print(i, d[-1])

# Write the last element then access all elements from the end
d[-1] = 4
print(d[-2], d[-1])

# Accessing indices out of bounds raises IndexError
try:
d[4]
Expand Down