raise_from breaks on PY3 when the base exception has multiple arguments #235

Closed
Antar1011 opened this Issue Sep 2, 2016 · 2 comments

Projects

None yet

3 participants

@Antar1011

Consider the following code:

from future.utils import raise_from

class MyException(Exception):

    def __init__(self, a, b):
        super(MyException, self).__init__('{0}: {1}'.format(a,7))

def foo():

    raise MyException(3, 7)

def bar():

    try:
        foo()
    except Exception as err:
        raise_from(ValueError('blue'), err)

Calling bar() works fine on PY2, but on PY3, one gets:

Traceback (most recent call last):
  File "blah.py", line 15, in bar
    foo()
  File "blah.py", line 10, in foo
    raise MyException(3, 7)
__main__.MyException: 3: 7

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "blah.py", line 27, in <module>
    bar()
  File "blah.py", line 17, in bar
    raise_from(ValueError('blue'), err)
  File "/Users/antar/Programming/.miniconda3/envs/futuristic/lib/python3.5/site-packages/future/utils/__init__.py", line 399, in raise_from
    exec(execstr, myglobals, mylocals)
  File "<string>", line 1, in <module>
TypeError: __init__() missing 1 required positional argument: 'b'

Basically, it looks like when future tries to re-create the exception, all it can do is parse the arguments as a single string (similar issue to #213).

@edschofield edschofield added a commit that referenced this issue Sep 22, 2016
@edschofield edschofield Add test for issue #235 efe07a0
@Daenyth
Daenyth commented Oct 26, 2016

Dupe #234?

@edschofield edschofield added a commit that referenced this issue Oct 27, 2016
@edschofield edschofield Fix tests for issue #235 25a86fe
@edschofield
Contributor

I think this is now fixed in v0.16.0. Please feel to re-open this if you notice any more problems. Thanks for reporting the bug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment