Weakref callback cleanup. This callable cleans out the state when it is being garbage collected. this _cleanup **assumes** that there are no strong refs to us! Will not work otherwise!
(self, ref: weakref.ref[_O])
| 538 | self.obj = lambda: None # type: ignore |
| 539 | |
| 540 | def _cleanup(self, ref: weakref.ref[_O]) -> None: |
| 541 | """Weakref callback cleanup. |
| 542 | |
| 543 | This callable cleans out the state when it is being garbage |
| 544 | collected. |
| 545 | |
| 546 | this _cleanup **assumes** that there are no strong refs to us! |
| 547 | Will not work otherwise! |
| 548 | |
| 549 | """ |
| 550 | |
| 551 | # Python builtins become undefined during interpreter shutdown. |
| 552 | # Guard against exceptions during this phase, as the method cannot |
| 553 | # proceed in any case if builtins have been undefined. |
| 554 | if dict is None: |
| 555 | return |
| 556 | |
| 557 | instance_dict = self._instance_dict() |
| 558 | if instance_dict is not None: |
| 559 | instance_dict._fast_discard(self) |
| 560 | del self._instance_dict |
| 561 | |
| 562 | # we can't possibly be in instance_dict._modified |
| 563 | # b.c. this is weakref cleanup only, that set |
| 564 | # is strong referencing! |
| 565 | # assert self not in instance_dict._modified |
| 566 | |
| 567 | self.session_id = self._strong_obj = None |
| 568 | |
| 569 | @property |
| 570 | def dict(self) -> _InstanceDict: |