Antoine Pitrou added the comment:

Antony, if you write (line numbers added for clarity):

1. try:
2.    d[obj]
3. except KeyError:
4.    d[obj] = some new value...
5. # expect d[obj] to exist at this point

it is possible that d[obj] still exists at line 2 but not anymore at line 5 
(because there would have been a garbage collection run in-between), at least 
if the original key is not `obj` but some other object equal to `obj`.  Using 
setdefault() would ensure that doesn't happen.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue31254>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to