https://github.com/python/cpython/commit/d927542e66b98082f6a99e96fa95063009bb3a88
commit: d927542e66b98082f6a99e96fa95063009bb3a88
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-11-12T19:58:51+02:00
summary:

[3.14] gh-158166: Make ElementTree ParseError messages strings (GH-158168) 
(GH-161885)

(cherry picked from commit 9894dc7af5e1e095467b41648c0572d76280c001)

Co-authored-by: Alex Prengère <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-09-26-09-44-59.gh-issue-158166.lVGCsI.rst
M Lib/test/test_xml_etree.py
M Lib/xml/etree/ElementTree.py

diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 960b706867a12d2..941adbff8ebdd67 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -1095,6 +1095,11 @@ def test_parse_error_after_chunk_boundary(self):
             ET.fromstring('<r>%s<</r>' % ('x' * size))
         self.assertEqual(cm.exception.position, (1, size + 4))
 
+    def test_parse_error_msg_is_string(self):
+        with self.assertRaises(ET.ParseError) as cm:
+            ET.XML("<")
+        self.assertIsInstance(cm.exception.msg, str)
+        self.assertEqual(cm.exception.msg, "unclosed token: line 1, column 0")
 
     def test_methods(self):
         # Test serialization methods.
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index b33005ad7f7dee3..e5ab27e7b15f912 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -1636,7 +1636,7 @@ def handler(pi_target, data, event=event_name, 
append=append,
                 raise ValueError("unknown event %r" % event_name)
 
     def _raiseerror(self, value):
-        err = ParseError(value)
+        err = ParseError(str(value))
         err.code = value.code
         err.position = value.lineno, value.offset
         raise err
diff --git 
a/Misc/NEWS.d/next/Library/2026-09-26-09-44-59.gh-issue-158166.lVGCsI.rst 
b/Misc/NEWS.d/next/Library/2026-09-26-09-44-59.gh-issue-158166.lVGCsI.rst
new file mode 100644
index 000000000000000..528160a6709369a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-09-26-09-44-59.gh-issue-158166.lVGCsI.rst
@@ -0,0 +1 @@
+Fix the type of the ``msg`` attribute of 
:exc:`xml.etree.ElementTree.ParseError` in the pure Python implementation: it 
is now a string, as in the C implementation.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to