Skip to content

Commit b46ea90

Browse files
committed
Issue python#29119: Fix weakref in OrderedDict.move_to_end(). Work by Andra Bogildea.
1 parent 6b5e4a8 commit b46ea90

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Lib/collections/__init__.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,22 @@ def move_to_end(self, key, last=True):
189189
link = self.__map[key]
190190
link_prev = link.prev
191191
link_next = link.next
192+
soft_link = link_next.prev
192193
link_prev.next = link_next
193194
link_next.prev = link_prev
194195
root = self.__root
195196
if last:
196197
last = root.prev
197198
link.prev = last
198199
link.next = root
199-
last.next = root.prev = link
200+
root.prev = soft_link
201+
last.next = link
200202
else:
201203
first = root.next
202204
link.prev = root
203205
link.next = first
204-
root.next = first.prev = link
206+
first.prev = soft_link
207+
root.next = link
205208

206209
def __sizeof__(self):
207210
sizeof = _sys.getsizeof

Misc/ACKS

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ Finn Bock
156156
Paul Boddie
157157
Matthew Boedicker
158158
Robin Boerdijk
159+
Andra Bogildea
159160
David Bolen
160161
Wouter Bolsterlee
161162
Gawain Bolton

Misc/NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ Library
143143
- Issue #13051: Fixed recursion errors in large or resized
144144
curses.textpad.Textbox. Based on patch by Tycho Andersen.
145145

146+
- Issue #29119: Fix weakrefs in the pure python version of
147+
collections.OrderedDict move_to_end() method.
148+
Contributed by Andra Bogildea.
149+
146150
- Issue #9770: curses.ascii predicates now work correctly with negative
147151
integers.
148152

0 commit comments

Comments
 (0)