I have some python code that's throwing a KeyError exception. So far I haven't been able to reproduce outside of the operating environment, so I can't post a reduced test case here.
The code that's raising the exception is iterating through a loop like this:
for k in d.keys():
if condition:
del d[k]
The del[k]
line throws the exception. I've added a try/except
clause around it and have been able to determine that k in d
is False, but k in d.keys()
is True.
The keys of d
are bound methods of old-style class instances.
The class implements __cmp__
and __hash__
, so that's where I've been focusing my attention.