-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
UnboundLocalError appeared in lazy-loader 0.4 #136
Comments
Thanks for the report @Bingshuang0u0; I'll take a look. |
I don't fully understand what this try-finally block is doing for us. It will delete before returning or raising, but I think the following should get you the same result, while allowing # Can raise without triggering finally
parent = inspect.stack()[1]
# Can raise AttributeError
try:
frame_data = {
"filename": parent.filename,
"lineno": parent.lineno,
"function": parent.function,
"code_context": parent.code_context,
}
finally:
del parent
# Parent is deleted, so we can safely raise anything here
return DelayedImportErrorModule(
frame_data,
"DelayedImportErrorModule",
message=not_found_message,
) That said, I don't think any of those attribute lookups on parent = inspect.stack()[1]
frame_data = {
"filename": parent.filename,
"lineno": parent.lineno,
"function": parent.function,
"code_context": parent.code_context,
}
del parent
return DelayedImportErrorModule(
frame_data,
"DelayedImportErrorModule",
message=not_found_message,
) |
I agree that it is very unlikely that an exception will occur during the construction of the Blame shows the finally clause was added in #4 presumably to remove the But of course the I don't know any reason to worry about deleting variable pointers like So, I think @effigies suggestion of removing the |
Great, thanks for the suggestions y'all. Did anyone make a PR, or should I go ahead? |
Sure, just opened #137. |
I was using librosa.load() which uses lazy-loader, and the error below appeared.
Error Message:
UnboundLocalError: local variable 'parent' referenced before assignment
The Code Where The Error Appeared:
This was mentioned in issue#79, but it happened again in version 0.4
Environment:
Python 3.9.13
lazy-loader 0.4
The text was updated successfully, but these errors were encountered: