Issue #21715: Extracted shared complicated code in the _io module to new
_PyErr_ChainExceptions() function.