Skip to content

Commit e52d652

Browse files
authored
Fix #15163 (CI: addon tests fail with Python 3.15 due to unclosed iterparse iterator in cppcheckdata.py) (#8984)
1 parent bc89c29 commit e52d652

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎addons/cppcheckdata.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838

3939
current_dumpfile_suppressions = []
4040

41+
def _iterparse(filename, events):
42+
# Open the file here so it is closed even when the caller stops iterating
43+
# early. Python 3.15 warns about unclosed iterparse iterators otherwise.
44+
with open(filename, 'rb') as f:
45+
yield from ElementTree.iterparse(f, events=events)
46+
47+
4148
def _load_location(location, element):
4249
"""Load location from element/dict"""
4350
location.file = element.get('file')
@@ -1237,7 +1244,7 @@ def __init__(self, filename):
12371244
# Parse general configuration options from <dumps> node
12381245
# We intentionally don't clean node resources here because we
12391246
# want to serialize in memory only small part of the XML tree.
1240-
for event, node in ElementTree.iterparse(self.filename, events=('start', 'end')):
1247+
for event, node in _iterparse(self.filename, events=('start', 'end')):
12411248
if platform_done and rawtokens_done and suppressions_done:
12421249
break
12431250
if node.tag == 'dumps':
@@ -1296,7 +1303,7 @@ def iterconfigurations(self):
12961303
# Use iterable objects to traverse XML tree for dump files incrementally.
12971304
# Iterative approach is required to avoid large memory consumption.
12981305
# Calling .clear() is necessary to let the element be garbage collected.
1299-
for event, node in ElementTree.iterparse(self.filename, events=('start', 'end')):
1306+
for event, node in _iterparse(self.filename, events=('start', 'end')):
13001307
# Serialize new configuration node
13011308
if node.tag == 'dump':
13021309
if event == 'start':

0 commit comments

Comments
 (0)