gh-140601: Add ResourceWarning to iterparse when not closed (GH-140603)

When iterparse() opens a file by filename and is not explicitly closed,
emit a ResourceWarning to alert developers of the resource leak.

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Osama Abdelkader 2025-11-13 20:05:28 +01:00 committed by GitHub
parent 209eaff68c
commit a486d452c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 69 additions and 4 deletions

View file

@ -656,6 +656,10 @@ Functions
.. versionchanged:: 3.13
Added the :meth:`!close` method.
.. versionchanged:: next
A :exc:`ResourceWarning` is now emitted if the iterator opened a file
and is not explicitly closed.
.. function:: parse(source, parser=None)