From 2c791484d7035a56e9599651ab56cf9287d41a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 31 Oct 2026 11:46:05 +0100 Subject: [PATCH 1/2] Fix #15163 (CI: addon tests fail with Python 3.15 due to unclosed iterparse iterator in cppcheckdata.py) --- addons/cppcheckdata.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index 06028e2005c..532121e61f1 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -38,6 +38,14 @@ current_dumpfile_suppressions = [] +def _iterparse(filename, events): + # Open the file here so it is closed even when the caller stops iterating + # early. Python 3.15 warns about unclosed iterparse iterators otherwise. + with open(filename, 'rb') as f: + for item in ElementTree.iterparse(f, events=events): + yield item + + def _load_location(location, element): """Load location from element/dict""" location.file = element.get('file') @@ -1237,7 +1245,7 @@ def __init__(self, filename): # Parse general configuration options from node # We intentionally don't clean node resources here because we # want to serialize in memory only small part of the XML tree. - for event, node in ElementTree.iterparse(self.filename, events=('start', 'end')): + for event, node in _iterparse(self.filename, events=('start', 'end')): if platform_done and rawtokens_done and suppressions_done: break if node.tag == 'dumps': @@ -1296,7 +1304,7 @@ def iterconfigurations(self): # Use iterable objects to traverse XML tree for dump files incrementally. # Iterative approach is required to avoid large memory consumption. # Calling .clear() is necessary to let the element be garbage collected. - for event, node in ElementTree.iterparse(self.filename, events=('start', 'end')): + for event, node in _iterparse(self.filename, events=('start', 'end')): # Serialize new configuration node if node.tag == 'dump': if event == 'start': From 0c120d2026a6047880abef5e0853f2a440247bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 31 Oct 2026 12:08:36 +0100 Subject: [PATCH 2/2] pylint --- addons/cppcheckdata.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index 532121e61f1..0d3e5d4cf29 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -42,8 +42,7 @@ def _iterparse(filename, events): # Open the file here so it is closed even when the caller stops iterating # early. Python 3.15 warns about unclosed iterparse iterators otherwise. with open(filename, 'rb') as f: - for item in ElementTree.iterparse(f, events=events): - yield item + yield from ElementTree.iterparse(f, events=events) def _load_location(location, element):