except dynamic_tuple:
fails to catch on Python 3
#2425
Labels
Milestone
except dynamic_tuple:
fails to catch on Python 3
#2425
Given this code in
foo.py
:Both Python 2 and Python 3 will print 'Caught':
But if we compile
foo.py
with Cython 0.28.3 and then invoke it, only Python 2 correctly catches the exception:The catch line compiles into a call to
__Pyx_PyErr_GivenExceptionMatches
The definitions of
__Pyx_inner_PyErr_GivenExceptionMatches2
are different on Python 2 and 3. On Python 2, it goes directly toPyObject_IsSubclass(err, exc_type)
, which correctly handles tuples.On Python 3, though, it calls
__Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
That's an incorrect cast in the second parameter, and
Pyx_IsSubtype
doesn't correctly handle tuples for its second argument (luckily it doesn't crash!). If I modify this function to usePyObject_IsSubclass
it works as expected.The text was updated successfully, but these errors were encountered: