Skip to content

gh-69893: Add the close() method for xml.etree.ElementTree.iterparse() iterator #114534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jan 24, 2024

@@ -608,6 +619,7 @@ def test_iterparse(self):
iterparse(SIMPLE_XMLFILE, events)
self.assertEqual(str(cm.exception), "unknown event 'bogus'")
del cm
gc_collect()
Copy link
Contributor

Choose a reason for hiding this comment

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

The added gc_collect() calls are redundant because the check_no_resource_warning() context manager already calls gc_collect().

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice. The initial version of my patch predates check_no_resource_warning().


def __del__(self):
# TODO: Emit a ResourceWarning if it was not explicitly closed.
Copy link
Member

Choose a reason for hiding this comment

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

Any plans for when this TODO will be done? They can end up languishing for decades :)

Copy link
Member Author

Choose a reason for hiding this comment

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

When all maintained Python versions have the close() method, so you can call it without checking the version.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe update the TODO to mention this, so when someone sees it they know whether they can do the TODO or wait a bit longer?

Anyway, I'll approve this.

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

Thanks!

@serhiy-storchaka serhiy-storchaka merged commit ca715e5 into python:main Feb 4, 2024
@serhiy-storchaka serhiy-storchaka deleted the etree-iterparse-close branch February 4, 2024 15:25
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull request Feb 14, 2024
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.

3 participants