Spaces:
Running
on
CPU Upgrade
Fix UnboundLocalError: local variable 'results' referenced before assignment
Fix UnboundLocalError: local variable 'results' referenced before assignment.
If there is a exception within the try
block, the variable results
is never defined.
This PR raises the exception (so we have information to fix it) after having cleaned up.
CC: @clefourrier
except Exception as e:
...
raise e
@clefourrier
the modification you proposed makes only sense if e
is used in the except clause, which is not the case here.
See: https://docs.python.org/3/tutorial/errors.html#raising-exceptions
If you need to determine whether an exception was raised but don’t intend to handle it, a simpler form of the raise statement allows you to re-raise the exception:
try:
raise NameError('HiThere')
except NameError:
print('An exception flew by!')
raise
See also: https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement
raise_stmt ::= "raise" [expression ["from" expression]]
If no expressions are present, raise re-raises the exception that is currently being handled, which is also known as the active exception.
Ha, got what you wanted to do, works for me then :)
Thanks for the details!