Skip to content

Commit

Permalink
Merge pull request #65 from doronz88/bugfix/override-globals
Browse files Browse the repository at this point in the history
hilda_client: fix override of globals from interactive shell
  • Loading branch information
doronz88 authored Jul 3, 2024
2 parents b3f79f8 + e2f9018 commit b7719f2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions hilda/hilda_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def __init__(self, debugger: lldb.SBDebugger):
self.configs = Configs()
self._dynamic_env_loaded = False
self._symbols_loaded = False
self.globals: typing.MutableMapping[str, Any] = globals()

# the frame called within the context of the hit BP
self._bp_frame = None
Expand Down Expand Up @@ -1060,8 +1061,7 @@ def interact(self, additional_namespace: Optional[typing.Mapping] = None,
ipython_config.InteractiveShellApp.exec_files = startup_files
self.log_debug(f'Startup files - {startup_files}')

namespace = globals()
namespace.update(locals())
namespace = self.globals
namespace['p'] = self
namespace['ui'] = self.ui_manager
namespace['cfg'] = self.configs
Expand All @@ -1076,11 +1076,10 @@ def __enter__(self) -> 'HildaClient':
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
self.detach()

@staticmethod
def _add_global(name: str, value: Any, reserved_names=None):
def _add_global(self, name: str, value: Any, reserved_names=None) -> None:
if reserved_names is None or name not in reserved_names:
# don't override existing symbols
globals()[name] = value
self.globals[name] = value

@staticmethod
def _get_saved_state_filename():
Expand Down
2 changes: 1 addition & 1 deletion hilda/ipython_extensions/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def pre_run_cell(self, info):
# we are only interested in names
continue

if node.id in locals() or node.id in globals() or node.id in dir(builtins):
if node.id in locals() or node.id in self.hilda_client.globals or node.id in dir(builtins):
# That are undefined
continue

Expand Down

0 comments on commit b7719f2

Please sign in to comment.