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
| 275 | |
| 276 | |
| 277 | class 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 | |
| 298 | class WeakKeyDictionary(_collections_abc.MutableMapping): |
no outgoing calls
no test coverage detected
searching dependent graphs…