On 2016-10-10, at 11:05 , Devin Jeanpierre
wrote: The term "borrowed" is supposed to imply a sensible scope during which you're free to use the object, and weakrefs don't have that (except for what is granted by the GIL), so this does sound wacky. I bet it was for performance.
Especially as it handles both getting an object from a weakref and checking whether the weakref is still alive. OTOH it could be an enshrined bug, http://bugs.python.org/issue520087 fixed a discrepancy between the doc and the implementation by matching the doc to the implementation (of returning a borrowed ref'). Also of note, pypy developers have been reporting issues with that specific API since ~2010[0][1], and IIRC they have added a PyWeakref_LockObject to cpyext. [0] http://bugs.python.org/issue8578 [1] http://bugs.python.org/issue16602#msg177272