python interface: make rethrow Python 3 compatible
commit99bf338d087f91cf9a539da56d1e9654a5de5f29
authorChielo Newctle <chielonewctle@gmail.com>
Wed, 24 Feb 2021 15:19:36 +0000 (24 15:19 +0000)
committerSven Verdoolaege <sven.verdoolaege@gmail.com>
Thu, 4 Mar 2021 22:55:43 +0000 (4 23:55 +0100)
tree0e2712678802d41b61901de4fbc04fab19350114
parent751f6ac18408d70e84afbc3a77a901db8867191a
python interface: make rethrow Python 3 compatible

The original approach works fine with Python 2.7 but not with Python 3.
Python 3 will give "TypeError: exceptions must derive from BaseException"
when using the original approach throwing tuples.

Instead, store the caught exceptions and rethrow them.
This works not only in Python 3, but also in Python 2.7 and Python 2.6.
An additional advantage is that traceback information is preserved
in the exception object when using Python 3.

An alternative approach would be to use "nonlocal"
to store exceptions into the outer scope, but this would
not work in Python 2.
Even though Python 2 is no longer supported
by the Python Software Foundation, it is still better
to try and preserve compatibility with Python 2.

Signed-off-by: Chielo Newctle <ChieloNewctle@Yandex.com>
Signed-off-by: Sven Verdoolaege <sven.verdoolaege@gmail.com>
interface/python.cc