Python __name__ variable not correct #2356#2438
Merged
jmthomas merged 1 commit intoOpenC3:mainfrom Oct 25, 2025
Merged
Conversation
mcosgriff
approved these changes
Oct 14, 2025
Contributor
mcosgriff
left a comment
There was a problem hiding this comment.
Verified output for for a single script and python files loaded with load_utility
test1.py
ryanmelt
requested changes
Oct 16, 2025
71c84c4 to
bfd53bc
Compare
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2438 +/- ##
==========================================
+ Coverage 79.55% 79.64% +0.09%
==========================================
Files 658 658
Lines 50378 50418 +40
Branches 736 736
==========================================
+ Hits 40076 40156 +80
+ Misses 10222 10182 -40
Partials 80 80
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Closes #2356
Adds
__name__and__file__to the script globals/bindings dict passed intoexec()based on reasonable values from theRunningScriptclass.Assumptions
openc3.utilities.running_script. Instead, we'd prefer its value is "main"start()should inherit "name" from the calling script. If it's not set, set it to "main". I think this makes sense to do. Sinceexec()is ultimately called, it should print the "name" for the active namespace. If this isn't set, it will showopenc3.utilities.running_scriptlike before. Defaulting to "main" is a reasonable alternative.Validation
Output
Output after running
test.py(looks expected ✅):Also validated that debug prints the expected values.
Open questions
I wasn't sure how to import
start()withinmark_testmodule if that's even possible. If so, please let me know! One thing I tried was passing the start func via closure into a func in the module. However, "name" would correctly(?) resolve to the caller's ("main") instead of the module name ("mark_test"). I think because the scope of the closure was ultimately intest.py: