From 117126bf8324fed7c1ceb2a35ab93a9a74cf0d81 Mon Sep 17 00:00:00 2001 From: M Bussonnier Date: Fri, 20 Sep 2024 10:44:43 +0200 Subject: [PATCH] Disable overriding of global breakpoint. Add a fallback option if still used Closes #357 --- lib/python/pyflyby/_dbg.py | 23 ++++++++++++----------- lib/python/pyflyby/_interactive.py | 2 +- lib/python/pyflyby/_py.py | 17 ++++++++++++++--- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/lib/python/pyflyby/_dbg.py b/lib/python/pyflyby/_dbg.py index 26f56a04..e1214680 100644 --- a/lib/python/pyflyby/_dbg.py +++ b/lib/python/pyflyby/_dbg.py @@ -909,23 +909,24 @@ def enable_faulthandler(): faulthandler.enable() -def add_debug_functions_to_builtins(): - ''' +def add_debug_functions_to_builtins(*, add_deprecated: bool): + """ Install debugger(), etc. in the builtin global namespace. - ''' + """ functions_to_add = [ 'debugger', 'debug_on_exception', 'print_traceback', ] - # DEPRECATED: In the future, the following will not be added to builtins. - # Use debugger() instead. - functions_to_add += [ - 'breakpoint', - 'debug_exception', - 'debug_statement', - 'waitpoint', - ] + if add_deprecated: + # DEPRECATED: In the future, the following will not be added to builtins. + # Use debugger() instead. + functions_to_add += [ + "breakpoint", + "debug_exception", + "debug_statement", + "waitpoint", + ] for name in functions_to_add: setattr(builtins, name, globals()[name]) diff --git a/lib/python/pyflyby/_interactive.py b/lib/python/pyflyby/_interactive.py index b3b8c031..9013fcda 100644 --- a/lib/python/pyflyby/_interactive.py +++ b/lib/python/pyflyby/_interactive.py @@ -2459,7 +2459,7 @@ def load_ipython_extension(arg=Ellipsis): enable_faulthandler() enable_signal_handler_debugger() enable_sigterm_handler(on_existing_handler='keep_existing') - add_debug_functions_to_builtins() + add_debug_functions_to_builtins(add_deprecated=False) inject_dynamic_import() initialize_comms() diff --git a/lib/python/pyflyby/_py.py b/lib/python/pyflyby/_py.py index ee65d71e..3da73932 100644 --- a/lib/python/pyflyby/_py.py +++ b/lib/python/pyflyby/_py.py @@ -30,6 +30,12 @@ py nb Start IPython Notebook with autoimporter + py [--add-deprecated-builtins] Inject "breakpoint", "debug_exception", + "debug_statement", "waitpoint" into + builtins. This is deprecated, and + present for backward compatibilty + but will be removed in the future. + Features ======== @@ -1688,6 +1694,7 @@ def start_ipython(self, args=[]): def _parse_global_opts(self): args = list(self.main_args) + self.add_deprecated_builtins = False self.debug = False self.interactive = False self.verbosity = 1 @@ -1791,6 +1798,10 @@ def novalue(): novalue() postmortem = False continue + if argname in ["add-deprecated-builtins", "add_deprecated_builtins"]: + del args[0] + self.add_deprecated_builtins = True + continue break self.args = args if postmortem == "auto": @@ -1798,18 +1809,18 @@ def novalue(): global _enable_postmortem_debugger _enable_postmortem_debugger = postmortem - def _enable_debug_tools(self): + def _enable_debug_tools(self, *, add_deprecated: bool): # Enable a bunch of debugging tools. enable_faulthandler() enable_signal_handler_debugger() enable_sigterm_handler() - add_debug_functions_to_builtins() + add_debug_functions_to_builtins(add_deprecated=add_deprecated) def run(self): # Parse global options. sys.orig_argv = list(sys.argv) self._parse_global_opts() - self._enable_debug_tools() + self._enable_debug_tools(add_deprecated=self.add_deprecated_builtins) self._run_action() self._pre_exit()