I made a patch to fix the problem. The cleaning up of they weakref keys or
values will be held until all references to iterators created by the
weakdict are dead.
I also couldn't resist removing code duplication of code in items(),
keys() and values().
At first, I couldn't understand why this whole remove(), _remove() and
selfref() mechanism was in place. I had removed them and replaced them
with methods, and the tests still passed. Then I realized it was to make
sure keys and values didn't prevent the weak dicts from being freed. I
added tests for this.