A common use of WeakKeyDictionary is to attach some private metadata to a potentially immutable object.
a WeakKeyDictionary is currently used in Trio to mark code objects as “keyboard interrupt protected”, in anyio a WeakKeyDictionary is used to make a task to its nearest parent CancelScope
I’ve recently been informed by @kumaraditya303 that WeakKeyDictionary is no longer suitable for this usecase on free-threading due to lock contention
I was wondering if a C acceleration version of WeakKeyDictionary, SimpleWeakKeyDictionary could be created that does not need a lock, by preventing iteration and using identity key semantics