| 102 | |
| 103 | |
| 104 | def _collection_gced(ref: weakref.ref[Any]) -> None: |
| 105 | # defaultdict, so can't get a KeyError |
| 106 | if not _collection_to_key or ref not in _collection_to_key: |
| 107 | return |
| 108 | |
| 109 | ref = cast("weakref.ref[RefCollection[EventTarget]]", ref) |
| 110 | |
| 111 | listener_to_key = _collection_to_key.pop(ref) |
| 112 | for key in listener_to_key.values(): |
| 113 | if key in _key_to_collection: |
| 114 | # defaultdict, so can't get a KeyError |
| 115 | dispatch_reg = _key_to_collection[key] |
| 116 | dispatch_reg.pop(ref) |
| 117 | if not dispatch_reg: |
| 118 | _key_to_collection.pop(key) |
| 119 | |
| 120 | |
| 121 | def _stored_in_collection( |