Skip to content

Fix warning with python 3.15 - #8985

Closed
pfultz2 wants to merge 1 commit into
cppcheck-opensource:mainfrom
pfultz2:py-3.15
Closed

pfultz2 wants to merge 1 commit into
cppcheck-opensource:mainfrom
pfultz2:py-3.15

Conversation

@pfultz2

@pfultz2 pfultz2 commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

The build (macos-15) job started failing because the runner's Homebrew Python moved from 3.14 to 3.15. The addon tests run pytest with -Werror, and Python 3.15 emits ResourceWarning: unclosed iterparse iterator when an iterparse iterator that opened its own file is dropped before it is exhausted. cppcheckdata.py does that in two places: CppcheckData.__init__ breaks out of the loop once it has the platform, raw tokens and suppressions, and iterconfigurations() is a generator that the caller can abandon early. The warning turned 11 addon tests into failures.

The change passes iterparse a file object opened in a with block instead of the filename. Then iterparse doesn't own the file, so there is nothing for Python 3.15 to warn about, and the file is closed when the block exits regardless of how the loop ends. Older Pythons behave the same as before. The rest of the diff is re-indentation of the loop bodies.

This is actually the same change was made in #8819, but this is moved out into a seperate PR so other PRs can start passing CI.

@pfultz2
pfultz2 requested review from danmar and a balanced review from Copilot October 31, 2026 16:06
@pfultz2

pfultz2 commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator Author

Oops, looks like @danmar already merged in a fix.

@pfultz2 pfultz2 closed this Oct 31, 2026
@pfultz2
pfultz2 deleted the py-3.15 branch October 31, 2026 16:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the explicit file ownership and cleanup changes.

No open issues 🎉

What changed in this PR

Addresses Python 3.15 resource warnings that cause addon tests to fail under -Werror, separating the file-handling fix from the broader changes in #8819.

Changes:

  • Passes explicitly opened binary files to ElementTree.iterparse in both parsing methods.
  • Uses context managers to close files when parsing exits or the configuration generator closes, preserving existing parsing logic.
File Description
addons/​cppcheckdata.py Adds explicit file ownership and cleanup to CppcheckData.__init__ and iterconfigurations(), with corresponding re-indentation and explanatory comments.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants