[New-bugs-announce] [issue21173] WeakKeyDictionary.__len__ fragile w/ _IterationGuards

Philip Jenvey report at bugs.python.org
Mon Apr 7 22:17:27 CEST 2014


New submission from Philip Jenvey:

len() on WeakKeyDictionarys can fail with ValueErrors when _IterationGuards are kept alive

Attached is a test showing this:

======================================================================
ERROR: test_weak_keys_len_destroy_while_iterating (__main__.MappingTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Lib/test/test_weakref.py", line 1336, in test_weak_keys_len_destroy_while_iterating
    self.assertEqual(len(dict), 0)
ValueError: __len__() should return >= 0


One probably shouldn't keep them alive like this, but __len__ shouldn't be blowing up either. On non ref counting GC platforms this situation is easier to trigger unintentionally

----------
components: Library (Lib)
messages: 215716
nosy: pitrou, pjenvey
priority: normal
severity: normal
status: open
title: WeakKeyDictionary.__len__ fragile w/ _IterationGuards
type: behavior
versions: Python 3.2, Python 3.3, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21173>
_______________________________________


More information about the New-bugs-announce mailing list