-
Notifications
You must be signed in to change notification settings - Fork 530
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
FIX: evaluate_connect_function should raise error on un-nested imports #3655
Conversation
24c42a8
to
cfa80c0
Compare
I think this is probably a change in Python's error messages, which should not be relied upon as an API. We should probably just do: except NameError as e:
e.args = (
*e.args,
"Due to engine constraints all imports have to be done inside each function definition"
)
raise e |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3655 +/- ##
=========================================
Coverage 70.85% 70.85%
=========================================
Files 1277 1277
Lines 59118 59116 -2
Branches 9803 8596 -1207
=========================================
- Hits 41888 41887 -1
- Misses 16061 16084 +23
+ Partials 1169 1145 -24 ☔ View full report in Codecov by Sentry. |
This incorporates Chris's suggestions from nipy#3655 (comment) Except I raise a new error and include the original error message (instead of revising the original error message). Co-authored-by: Chris Markiewicz <effigies@gmail.com>
Thanks @effigies , I think that is a nice idea (much simpler). I incorporated this suggestion in 4e0b503 , except that I just explicitly raise a |
…ect_function more permissive the if-statement in this function is very specific and ensures that the error message both starts with "global name" and ends with "is not defined" before raising the informative error about nested imports. nipreps/nibabies#365 gives one example where this if-statement is too specific, and doesn't catch a NameError that does actually arise from a module-level import.
This incorporates Chris's suggestions from nipy#3655 (comment) Except I raise a new error and include the original error message (instead of revising the original error message). Co-authored-by: Chris Markiewicz <effigies@gmail.com>
4e0b503
to
df241b2
Compare
Summary
if I'm understanding evaluate_connect_function correctly, the intent of the if-clause is to catch errors that arise from calling libraries/modules/functions that were imported at the module level (as opposed to nesting the imports at the function level), and raises a more informative error for those cases.
I think nipreps/nibabies#365 gives one example where the if-clause should catch such an error, but doesn't, because the error doesn't start with
"global name"
. So I think it should be okay to make the if-clause more permissive, i.e. just check if the error message ends with"is not defined"
, then return the extra-informative error message to the user.What do you think?