raise_from throws NameError when the second parameter is an exception imported via import <module>.
See this commit where I had to work around it:
I suspect the problem is with _repr_strip, but I could not confirm: https://github.com/PythonCharmers/python-future/blob/master/src/future/utils/__init__.py#L397
This happens because raise_from tries to recreate the exact expression used to create the exception. Of course, this fails when the exception's repr method doesn't match up with the expression, or when the expression can't be directly evaluated.
It seems to me that the proper fix here would be to shove the 'exc' and 'cause' parameter values into the dictionaries passed into the 'exec' call:
def raise_from(exc, cause):
raise EXCEPTION from CAUSE
on Python 3. (See PEP 3134).
myglobals, mylocals = _get_caller_globals_and_locals()
myglobals = myglobals.copy()
myglobals['___python_future_raise_from_exc'] = exc
myglobals['___python_future_raise_from_cause'] = cause
execstr = "raise __python_future_raise_from_exc from __python_future_raise_from_cause"
exec(execstr, myglobals, mylocals)
Add fix for issues #235 and (probably) #213
Update docs re issues #235, #213
Shoshana, thanks for reporting this! I think this is fixed now in v0.16.0 with @Varriount's patch. Please feel free to re-open this if you see any more problems.