Skip to content

Commit

Permalink
Merge pull request #358 from Carreau/dep-1
Browse files Browse the repository at this point in the history
Disable overriding of global breakpoint.
  • Loading branch information
Carreau authored Sep 20, 2024
2 parents 7fcf962 + 117126b commit a2045de
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
23 changes: 12 additions & 11 deletions lib/python/pyflyby/_dbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
2 changes: 1 addition & 1 deletion lib/python/pyflyby/_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
17 changes: 14 additions & 3 deletions lib/python/pyflyby/_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
========
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1791,25 +1798,29 @@ 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":
postmortem = os.isatty(1)
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()

Expand Down

0 comments on commit a2045de

Please sign in to comment.