-
Notifications
You must be signed in to change notification settings - Fork 294
Closed
Description
When the future.utils.raise_ function is used with all its three parameters, it is in some cases not able to reraise exceptions which need arguments for their initialization. For example, this code:
import sys
from future.utils import raise_
class CustomException(Exception):
def __init__(self, severity: int, message: str) -> None:
super().__init__(f"custom message of severity {severity}: {message}")
try:
raise CustomException(1, "hello")
except CustomException:
raise_(*sys.exc_info())fails with a TypeError:
Traceback (most recent call last):
File "./future_test.py", line 11, in <module>
raise CustomException(1, "hello")
__main__.CustomException: custom message of severity 1: hello
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./future_test.py", line 13, in <module>
raise_(*sys.exc_info())
File "../python3.6/site-packages/future/utils/__init__.py", line 409, in raise_
exc = tp(value)
TypeError: __init__() missing 1 required positional argument: 'message'
The problem is caused by the fact that the raise_ function tries to initialize the exception class (i.e. its first argument) using exception value (i.e. its second argument):
python-future/src/future/utils/__init__.py
Line 410 in 3c44a1e
| exc = tp(value) |
That is not always possible for exception types with custom initializers.