Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hilda_client: fix override of globals from interactive shell #65

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading