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