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
| 333 | |
| 334 | |
| 335 | class KeyedRef(ref): |
| 336 | """Specialized reference that includes a key corresponding to the value. |
| 337 | |
| 338 | This is used in the WeakValueDictionary to avoid having to create |
| 339 | a function object for each key stored in the mapping. A shared |
| 340 | callback object can use the 'key' attribute of a KeyedRef instead |
| 341 | of getting a reference to the key from an enclosing scope. |
| 342 | |
| 343 | """ |
| 344 | |
| 345 | __slots__ = "key", |
| 346 | |
| 347 | def __new__(type, ob, callback, key): |
| 348 | self = ref.__new__(type, ob, callback) |
| 349 | self.key = key |
| 350 | return self |
| 351 | |
| 352 | def __init__(self, ob, callback, key): |
| 353 | super().__init__(ob, callback) |
| 354 | |
| 355 | |
| 356 | class WeakKeyDictionary(_collections_abc.MutableMapping): |
no outgoing calls
no test coverage detected