[issue17816] Weak*Dictionary KeyErrors during callbacks

2013-05-01 Thread Nils Bruin
Nils Bruin added the comment: One solution is to patch both WeakValueDictionary and WeakKeyDictionary with their own clear methods where we first store the strong links (to keys, resp. values) in a list, then clear the underlying dictionaries (this will now trigger the deletion of the

[issue17816] Weak*Dictionary KeyErrors during callbacks

2013-04-22 Thread Nils Bruin
Nils Bruin added the comment: I think the difference in behaviour between Py3 and Py2 is coming from: http://hg.python.org/cpython/file/a26df2d03989/Objects/dictobject.c#l1275 which first clears all values before removing any keys. For a WeakValueDictionary that means all the weakrefs are

[issue17816] Weak*Dictionary KeyErrors during callbacks

2013-04-22 Thread Nils Bruin
Nils Bruin added the comment: Have you tried if the fix at issue7105 solves the problem? I don't see the patch there introduce a `clear` method override for WeakValueDictionary or WeakKeyDictionary. The one for WeakSet still calls self.data.clear(), which for dictionaries would still r

[issue17816] Weak*Dictionary KeyErrors during callbacks

2013-04-22 Thread Nils Bruin
New submission from Nils Bruin: The following program is a little dependent on memory layout but will usually generate lots of Exception KeyError: (A(9996),) in ignored messages in Python 2.7. import weakref class A(object): def __init__(self,n): self.n=n

[issue17526] inspect.findsource raises undocumented error for code objects with empty filename

2013-03-25 Thread Nils Bruin
Nils Bruin added the comment: The most straightforward change I can think of is to change the line if not sourcefile and file[0] + file[-1] != '<>': to if not sourcefile and (not file or file[0] + file[-1] != '<>'): That solves the prob

[issue17526] inspect.findsource raises undocumented error for code objects with empty filename

2013-03-22 Thread Nils Bruin
New submission from Nils Bruin: It would seem reasonable that an empty filename would be a legitimate way of indicating that a code object does not have a corresponding source file. However, if one does that then inspect.findsource raises an unexpected IndexError rather than the documented