Modified Pdb class, does not load readline. for a standalone version that uses prompt_toolkit, see `IPython.terminal.debugger.TerminalPdb` and `IPython.terminal.debugger.set_trace()`
| 193 | |
| 194 | |
| 195 | class Pdb(OldPdb): |
| 196 | """Modified Pdb class, does not load readline. |
| 197 | |
| 198 | for a standalone version that uses prompt_toolkit, see |
| 199 | `IPython.terminal.debugger.TerminalPdb` and |
| 200 | `IPython.terminal.debugger.set_trace()` |
| 201 | """ |
| 202 | |
| 203 | def __init__(self, color_scheme=None, completekey=None, |
| 204 | stdin=None, stdout=None, context=5, **kwargs): |
| 205 | """Create a new IPython debugger. |
| 206 | |
| 207 | :param color_scheme: Deprecated, do not use. |
| 208 | :param completekey: Passed to pdb.Pdb. |
| 209 | :param stdin: Passed to pdb.Pdb. |
| 210 | :param stdout: Passed to pdb.Pdb. |
| 211 | :param context: Number of lines of source code context to show when |
| 212 | displaying stacktrace information. |
| 213 | :param kwargs: Passed to pdb.Pdb. |
| 214 | The possibilities are python version dependent, see the python |
| 215 | docs for more info. |
| 216 | """ |
| 217 | |
| 218 | # Parent constructor: |
| 219 | try: |
| 220 | self.context = int(context) |
| 221 | if self.context <= 0: |
| 222 | raise ValueError("Context must be a positive integer") |
| 223 | except (TypeError, ValueError): |
| 224 | raise ValueError("Context must be a positive integer") |
| 225 | |
| 226 | # `kwargs` ensures full compatibility with stdlib's `pdb.Pdb`. |
| 227 | OldPdb.__init__(self, completekey, stdin, stdout, **kwargs) |
| 228 | |
| 229 | # IPython changes... |
| 230 | self.shell = get_ipython() |
| 231 | |
| 232 | if self.shell is None: |
| 233 | save_main = sys.modules['__main__'] |
| 234 | # No IPython instance running, we must create one |
| 235 | from IPython.terminal.interactiveshell import \ |
| 236 | TerminalInteractiveShell |
| 237 | self.shell = TerminalInteractiveShell.instance() |
| 238 | # needed by any code which calls __import__("__main__") after |
| 239 | # the debugger was entered. See also #9941. |
| 240 | sys.modules['__main__'] = save_main |
| 241 | |
| 242 | if color_scheme is not None: |
| 243 | warnings.warn( |
| 244 | "The `color_scheme` argument is deprecated since version 5.1", |
| 245 | DeprecationWarning, stacklevel=2) |
| 246 | else: |
| 247 | color_scheme = self.shell.colors |
| 248 | |
| 249 | self.aliases = {} |
| 250 | |
| 251 | # Create color table: we copy the default one from the traceback |
| 252 | # module and add a few attributes needed for debugging |
no test coverage detected