Call up the pdb debugger if desired, always clean up the tb reference. Keywords: - force(False): by default, this routine checks the instance call_pdb flag and does not actually invoke the debugger if the flag is false. The 'force' option forces th
(self, force: bool = False)
| 996 | return structured_traceback_parts |
| 997 | |
| 998 | def debugger(self, force: bool = False) -> None: |
| 999 | """Call up the pdb debugger if desired, always clean up the tb |
| 1000 | reference. |
| 1001 | |
| 1002 | Keywords: |
| 1003 | |
| 1004 | - force(False): by default, this routine checks the instance call_pdb |
| 1005 | flag and does not actually invoke the debugger if the flag is false. |
| 1006 | The 'force' option forces the debugger to activate even if the flag |
| 1007 | is false. |
| 1008 | |
| 1009 | If the call_pdb flag is set, the pdb interactive debugger is |
| 1010 | invoked. In all cases, the self.tb reference to the current traceback |
| 1011 | is deleted to prevent lingering references which hamper memory |
| 1012 | management. |
| 1013 | |
| 1014 | Note that each call to pdb() does an 'import readline', so if your app |
| 1015 | requires a special setup for the readline completers, you'll have to |
| 1016 | fix that by hand after invoking the exception handler.""" |
| 1017 | |
| 1018 | if force or self.call_pdb: |
| 1019 | if self.pdb is None: |
| 1020 | self.pdb = self.debugger_cls() |
| 1021 | # the system displayhook may have changed, restore the original |
| 1022 | # for pdb |
| 1023 | display_trap = DisplayTrap(hook=sys.__displayhook__) |
| 1024 | with display_trap: |
| 1025 | self.pdb.reset() |
| 1026 | # Find the right frame so we don't pop up inside ipython itself |
| 1027 | if hasattr(self, "tb") and self.tb is not None: # type: ignore[has-type] |
| 1028 | etb = self.tb # type: ignore[has-type] |
| 1029 | else: |
| 1030 | etb = self.tb = sys.last_traceback |
| 1031 | while self.tb is not None and self.tb.tb_next is not None: |
| 1032 | assert self.tb.tb_next is not None |
| 1033 | self.tb = self.tb.tb_next |
| 1034 | if etb and etb.tb_next: |
| 1035 | etb = etb.tb_next |
| 1036 | self.pdb.botframe = etb.tb_frame |
| 1037 | # last_value should be deprecated, but last-exc sometimme not set |
| 1038 | # please check why later and remove the getattr. |
| 1039 | exc = ( |
| 1040 | sys.last_value |
| 1041 | if sys.version_info < (3, 12) |
| 1042 | else getattr(sys, "last_exc", sys.last_value) |
| 1043 | ) # type: ignore[attr-defined] |
| 1044 | if exc: |
| 1045 | self.pdb.interaction(None, exc) |
| 1046 | else: |
| 1047 | self.pdb.interaction(None, etb) |
| 1048 | |
| 1049 | if hasattr(self, "tb"): |
| 1050 | del self.tb |
| 1051 | |
| 1052 | def handler(self, info=None): |
| 1053 | (etype, evalue, etb) = info or sys.exc_info() |
no test coverage detected