MCPcopy Index your code
hub / github.com/python/cpython / KeyedRef

Class KeyedRef

Lib/weakref.py:277–295  ·  view source on GitHub ↗

Specialized reference that includes a key corresponding to the value. This is used in the WeakValueDictionary to avoid having to create a function object for each key stored in the mapping. A shared callback object can use the 'key' attribute of a KeyedRef instead of getting a refe

Source from the content-addressed store, hash-verified

275
276
277class KeyedRef(ref):
278 """Specialized reference that includes a key corresponding to the value.
279
280 This is used in the WeakValueDictionary to avoid having to create
281 a function object for each key stored in the mapping. A shared
282 callback object can use the 'key' attribute of a KeyedRef instead
283 of getting a reference to the key from an enclosing scope.
284
285 """
286
287 __slots__ = "key",
288
289 def __new__(type, ob, callback, key):
290 self = ref.__new__(type, ob, callback)
291 self.key = key
292 return self
293
294 def __init__(self, ob, callback, key):
295 super().__init__(ob, callback)
296
297
298class WeakKeyDictionary(_collections_abc.MutableMapping):

Callers 3

__setitem__Method · 0.70
setdefaultMethod · 0.70
updateMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…