Skip to content

Fix: Stop TDI execution from editing caller's Python namespace - #3082

Open
benjysmith wants to merge 5 commits into
MDSplus:alphafrom
benjysmith:fix-python-tdi-global-namespace
Open

Fix: Stop TDI execution from editing caller's Python namespace#3082
benjysmith wants to merge 5 commits into
MDSplus:alphafrom
benjysmith:fix-python-tdi-global-namespace

Conversation

@benjysmith

Copy link
Copy Markdown

Fixes #3081, where the observed symptom was __file__ being changed permanently to the path of the TDI function being executed.

The issue stems from using __main__ as a scratch pad to store the reference to the function being called, the __file__ variable, etc. The fix implemented here is to give each TDI function its own namespace to use: tdi_functions.<function name> instead of __main__. This also requires changing the Simple PyFun calls into normal ones as the Simple ones use the global namespace, and changing get_exec_file to use a provided namespace, rather than just __main__.__dict__.
This prevents the function's namespace from colliding with the caller, and also prevents potential collisions between different Python-implemented TDI functions.

Additionally, a test case for this was written, which checks that __file__ is modified when viewed from inside the TDI function, but not modified in the caller's namespace.

@benjysmith
benjysmith marked this pull request as ready for review August 11, 2026 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calling TDI functions implemented in Python permanently changes __file__

1 participant