Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a74993

Browse files
committed
PyErr_NormalizeException(): If the exception's type is a class and the
instance's class is a subclass of this, then use the instance's class as the exception type.
1 parent 22ecb71 commit 3a74993

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

Python/errors.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ PyErr_NormalizeException(exc, val, tb)
206206
Py_DECREF(value);
207207
value = res;
208208
}
209+
/* if the class of the instance doesn't exactly match the
210+
class of the type, believe the instance
211+
*/
212+
else if (inclass != type) {
213+
Py_DECREF(type);
214+
type = inclass;
215+
Py_INCREF(type);
216+
}
209217
}
210218
*exc = type;
211219
*val = value;

0 commit comments

Comments
 (0)