Issue #24102: Fixed exception type checking in standard error handlers.
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py
index b9cd9c2..c11affd 100644
--- a/Lib/test/test_codeccallbacks.py
+++ b/Lib/test/test_codeccallbacks.py
@@ -836,6 +836,26 @@
text = u'abc<def>ghi'*n
text.translate(charmap)
+ def test_fake_error_class(self):
+ handlers = [
+ codecs.strict_errors,
+ codecs.ignore_errors,
+ codecs.replace_errors,
+ codecs.backslashreplace_errors,
+ codecs.xmlcharrefreplace_errors,
+ ]
+ for cls in UnicodeEncodeError, UnicodeDecodeError, UnicodeTranslateError:
+ class FakeUnicodeError(str):
+ __class__ = cls
+ for handler in handlers:
+ self.assertRaises(TypeError, handler, FakeUnicodeError())
+ class FakeUnicodeError(Exception):
+ __class__ = cls
+ for handler in handlers:
+ with self.assertRaises((TypeError, FakeUnicodeError)):
+ handler(FakeUnicodeError())
+
+
def test_main():
test.test_support.run_unittest(CodecCallbackTest)