Skip to content

Commit bb49040

Browse files
committed
Do not modify dict while iterating over it.
1 parent 5d7ed06 commit bb49040

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/matplotlib/cbook.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,10 +1491,10 @@ def clean(self):
14911491
Clean dead weak references from the dictionary
14921492
"""
14931493
mapping = self._mapping
1494-
for key, val in mapping.iteritems():
1495-
if key() is None:
1496-
del mapping[key]
1497-
val.remove(key)
1494+
to_drop = [key for key in mapping if key() is None]
1495+
for key in to_drop:
1496+
val = mapping.pop(key)
1497+
val.remove(key)
14981498

14991499
def join(self, a, *args):
15001500
"""

0 commit comments

Comments
 (0)